!pip install scikit-learn !pip install umap-learn

In [2]:
from Bio import Entrez, SeqIO
In [3]:
Entrez.email = "osama2172003aldesoky.com"
query = "blaTEM AND Escherichia coli[Organism]"

retmax = 100
handle_search = Entrez.esearch(db="nucleotide", term=query, retmax=retmax)
search_results = Entrez.read(handle_search)
handle_search.close()
id_list = search_results["IdList"]
print(f" Number of retrieved sequences: {len(id_list)}")
handle_fetch = Entrez.efetch(db="nucleotide", id=id_list, rettype="fasta", retmode="text")
records = list(SeqIO.parse(handle_fetch, "fasta"))
handle_fetch.close()

print(f"Downloaded {len(records)} sequence from NCBI")
SeqIO.write(records, "tem1_sequences.fasta", "fasta")
print("The sequences were saved in a file: tem1_sequences.fasta")
print(search_results)
 Number of retrieved sequences: 100
Downloaded 93 sequence from NCBI
The sequences were saved in a file: tem1_sequences.fasta
{'Count': '26412', 'RetMax': '100', 'RetStart': '0', 'IdList': ['3024353050', '3023638427', '3023560251', '3023536798', '3022846721', '3022725241', '3022630913', '3022630876', '3020292345', '2752880018', '2524484095', '2255885729', '1148836538', '1119795159', '1119778745', '1103820147', '757605208', '692990478', '3015430272', '2752129683', '2521722531', '1888298469', '1862746456', '1853504665', '1816433663', '1816433658', '1816433652', '3012355828', '1883825494', '1866146194', '1836674118', '1816513184', '3010737428', '1848406648', '1800078768', '237640188', '1848406551', '1832836016', '410593098', '256367708', '1786223106', '2520284883', '2515153030', '1727822781', '1727822689', '1727822686', '1727822683', '1727822681', '1727822679', '1727822676', '1727822674', '1727822672', '1727822670', '1727822668', '1727822665', '1727822663', '1727822661', '1727822658', '1727822656', '1727822653', '1727822651', '1727822648', '1727822646', '1727822644', '1727822642', '1727822640', '1727822638', '1727822635', '1727822633', '1727822631', '1727822629', '1727822626', '1727822624', '1727822622', '1727822619', '1727822617', '1727822614', '1727822612', '1727822610', '1727822608', '1727822606', '1727822604', '1727822602', '1727822599', '1727822597', '1727822595', '1727822592', '1727822589', '1727822587', '1727822584', '1727822582', '1727822580', '1727822577', '1727822574', '1727822571', '1727822566', '1727822563', '1727822559', '1727822556', '1727822552'], 'TranslationSet': [{'From': 'Escherichia coli[Organism]', 'To': '"Escherichia coli"[Organism]'}], 'TranslationStack': [{'Term': 'blaTEM[All Fields]', 'Field': 'All Fields', 'Count': '1', 'Explode': 'N'}, {'Term': '"Escherichia coli"[Organism]', 'Field': 'Organism', 'Count': '1', 'Explode': 'Y'}, 'AND'], 'QueryTranslation': 'blaTEM[All Fields] AND "Escherichia coli"[Organism]'}
In [4]:
from Bio import SeqIO
import pandas as pd

# Load sequences from a fasta file
records = list(SeqIO.parse("tem1_sequences.fasta", "fasta"))
print(f" Number of original sequences: {len(records)}")

min_len = 100
max_len = 3000

# Filter sequences by length
filtered = [r for r in records if min_len <= len(r.seq) <= max_len]
print(f" Number of filtered sequences: {len(filtered)}")

# Save them to a new file for analysis
SeqIO.write(filtered, "filtered_sequences.fasta", "fasta")

# Save sequence lengths to a table CSV (for later visualization)
lengths = [len(r.seq) for r in filtered]
pd.DataFrame({"length": lengths}).to_csv("sequence_lengths.csv", index=False)

print(" Filtered sequences and statistical data saved")
 Number of original sequences: 93
 Number of filtered sequences: 47
 Filtered sequences and statistical data saved
In [5]:
import subprocess
from Bio import AlignIO
import pandas as pd

#1) Input and Output Files
input_file = "filtered_sequences.fasta"
output_file = "aligned_sequences.aln"


clustal_path = r"D:\Osama\biotec\Bioinformatics\mutation_structural_analysis_ncbi\clustal-omega-1.2.2-win64\clustal-omega-1.2.2-win64\clustalo.exe"


#2) Run Alignment
cline = ClustalOmegaCommandline(
cmd=clustal_path,
infile=input_file,
outfile=output_file,
verbose=True,
auto=True,
force=True
)
print(" Running Alignment...")
cline()
print(" Alignment completed")

#3) Read alignment
alignment = AlignIO.read(output_file, "fasta")
L = alignment.get_alignment_length()
print(f" Alignment length: {L} column")

#4) Extract SNPs with list comprehension
snp_df = pd.DataFrame([
{
"Position": pos + 1,
"Variants": "".join(sorted(set(alignment[:, pos]) - {"-", "N"}))
}
for pos in range(L)
if len(set(alignment[:, pos]) - {"-", "N"}) > 1
])

#5) Save results
snp_df.to_csv("snp_table.csv", index=False)
print(f" {len(snp_df)} SNP mutation location identified")
D:\Osama\biotec\Bioinformatics\mutation_structural_analysis_ncbi\venv\Lib\site-packages\Bio\Application\__init__.py:39: BiopythonDeprecationWarning: The Bio.Application modules and modules relying on it have been deprecated.

Due to the on going maintenance burden of keeping command line application
wrappers up to date, we have decided to deprecate and eventually remove these
modules.

We instead now recommend building your command line and invoking it directly
with the subprocess module.
  warnings.warn(
 Running Alignment...
 Alignment completed
 Alignment length: 2992 column
 2850 SNP mutation location identified
In [6]:
import numpy as np
from Bio import AlignIO

# 1) Read the alignment
alignment = AlignIO.read("aligned_sequences.aln", "fasta")
L = alignment.get_alignment_length()
n = len(alignment)

# 2) Calculate π for each column in one stroke
pi_values = []
for pos in range(L):
    column = alignment[:, pos]
    freqs = np.array([column.count(b) for b in set(column) if b not in ("-", "N")], float)
    total = freqs.sum()
    # Here we use ternary to avoid a lengthy if block
    pi_site = 0.0 if total < 2 else 1 - np.sum((freqs/total)**2)
    pi_values.append(pi_site)

# 3) π Total
pi_total = sum(pi_values) * 2 / (n * (n - 1))

#4) Print the result
print(f"📊 Number of sequences: {n}")
print(f"📊 Alignment length: {L}")
print(f"📊 Nucleotide diversity (π): {pi_total: .5f}")
📊 Number of sequences: 47
📊 Alignment length: 2992
📊 Nucleotide diversity (π):  1.57992
In [7]:
import numpy as np
import matplotlib.pyplot as plt
from Bio import AlignIO

alignment = AlignIO.read("aligned_sequences.aln", "fasta")
L = alignment.get_alignment_length()
n = len(alignment)

def pi_site(column):
    freqs = np.array(
        [column.count(b) for b in set(column) if b not in ("-", "N")],
        dtype=float
    )
    total = freqs.sum()
    return 0.0 if total < 2 else 1 - np.sum((freqs/total)**2)

window_size = 100
step = 10
windows = range(0, L - window_size + 1, step)

pi_window = []
for start in windows:
    site_vals = [pi_site(alignment[:, pos]) for pos in range(start, start + window_size)]
    pi_window.append(np.mean(site_vals))

positions = [w + window_size/2 for w in windows]
plt.figure(figsize=(8, 4))
plt.plot(positions, pi_window, marker='o', linestyle='-')
plt.title("Sliding Window π (window=100, step=10)")
plt.xlabel("Position in alignment")
plt.ylabel("Nucleotide diversity (π)")
plt.grid(True)
plt.savefig("sliding_window_pi.png", dpi=300, bbox_inches='tight')
plt.show()
No description has been provided for this image
In [9]:
import numpy as np
from sklearn.decomposition import PCA
import matplotlib.pyplot as plt

bases = ["A","T","G","C"]
n, L = len(alignment), alignment.get_alignment_length()
X = np.zeros((n, L * 4), dtype=int)
for i, record in enumerate(alignment):
    for j, b in enumerate(record.seq.upper()):
        if b in bases:
            X[i, 4*j + bases.index(b)] = 1

pca = PCA(n_components=2)
coords = pca.fit_transform(X)

plt.figure(figsize=(6, 5))
plt.scatter(coords[:, 0], coords[:, 1], c='skyblue', s=50)
plt.title("PCA of TEM-1 Sequences")
plt.xlabel("PC1")
plt.ylabel("PC2")
plt.grid(True)

plt.savefig("pca_plot.png", dpi=300, bbox_inches='tight')
plt.show()
No description has been provided for this image
In [10]:
import umap

reducer = umap.UMAP(n_components=2, random_state=42)
umap_coords = reducer.fit_transform(X)

plt.figure(figsize=(6, 5))
plt.scatter(umap_coords[:, 0], umap_coords[:, 1], c='salmon', s=50)
plt.title("UMAP of TEM-1 Sequences")
plt.xlabel("UMAP1")
plt.ylabel("UMAP2")
plt.grid(True)

plt.savefig("umap_plot.png", dpi=300, bbox_inches='tight')
plt.show()
D:\Osama\biotec\Bioinformatics\mutation_structural_analysis_ncbi\venv\Lib\site-packages\umap\umap_.py:1952: UserWarning: n_jobs value 1 overridden to 1 by setting random_state. Use no seed for parallelism.
  warn(
No description has been provided for this image
In [8]:
import numpy as np

pi_arr = np.array(pi_window)
high_thresh = np.percentile(pi_arr, 85)
low_thresh  = np.percentile(pi_arr, 15)

high_windows = [(positions[i], pi_arr[i])
                for i in range(len(pi_arr)) if pi_arr[i] >= high_thresh]
low_windows  = [(positions[i], pi_arr[i])
                for i in range(len(pi_arr)) if pi_arr[i] <= low_thresh]

print("High-diversity windows (pos, π):", high_windows)
print("Low-diversity windows (pos, π):",  low_windows)
High-diversity windows (pos, π): [(150.0, np.float64(0.6194133913237322)), (160.0, np.float64(0.6238210764893016)), (170.0, np.float64(0.6269075174772505)), (180.0, np.float64(0.6264379117308381)), (190.0, np.float64(0.6290302638596323)), (200.0, np.float64(0.6268832566688626)), (210.0, np.float64(0.6211521322937988)), (220.0, np.float64(0.6245821096472878)), (230.0, np.float64(0.632330266394394)), (240.0, np.float64(0.6202068988747873)), (660.0, np.float64(0.6185442120759767)), (680.0, np.float64(0.6232323801244771)), (690.0, np.float64(0.6266312744831919)), (700.0, np.float64(0.6376965494430101)), (710.0, np.float64(0.6319625927550881)), (720.0, np.float64(0.6376708147035726)), (730.0, np.float64(0.6427499240856092)), (740.0, np.float64(0.6369460678619772)), (750.0, np.float64(0.6378695972206083)), (760.0, np.float64(0.6325286551339384)), (770.0, np.float64(0.6397499468792047)), (780.0, np.float64(0.6389291897791651)), (790.0, np.float64(0.6354235601745633)), (800.0, np.float64(0.6414001178458668)), (810.0, np.float64(0.6460733394148548)), (820.0, np.float64(0.6447803825109581)), (830.0, np.float64(0.6440718806194045)), (840.0, np.float64(0.6389259500240747)), (850.0, np.float64(0.6351852817527955)), (1140.0, np.float64(0.6287017844995062)), (1150.0, np.float64(0.6340242855325152)), (1160.0, np.float64(0.6293387232399913)), (1170.0, np.float64(0.6199562070030439)), (1180.0, np.float64(0.6282510797453166)), (1190.0, np.float64(0.6265910446436022)), (1200.0, np.float64(0.618444735452277)), (1210.0, np.float64(0.6201567889327153)), (1230.0, np.float64(0.6190612857510661)), (1240.0, np.float64(0.6184538889347068)), (1380.0, np.float64(0.6184536447158272)), (1420.0, np.float64(0.6233475998332599)), (1430.0, np.float64(0.6194569109284191)), (1440.0, np.float64(0.6215519563573815)), (1450.0, np.float64(0.6204488580652044))]
Low-diversity windows (pos, π): [(50.0, np.float64(0.4723771762408667)), (60.0, np.float64(0.5079854528848576)), (70.0, np.float64(0.5030212506535225)), (80.0, np.float64(0.5262029329516885)), (310.0, np.float64(0.5138096412562799)), (320.0, np.float64(0.49636393261027406)), (330.0, np.float64(0.48520344391289716)), (340.0, np.float64(0.4712885428977724)), (350.0, np.float64(0.5051767737953351)), (360.0, np.float64(0.48156018544382984)), (370.0, np.float64(0.4809684585858406)), (380.0, np.float64(0.49139402259376125)), (390.0, np.float64(0.5000110029055135)), (400.0, np.float64(0.507913850106913)), (910.0, np.float64(0.5253354193503351)), (920.0, np.float64(0.5251904889765712)), (930.0, np.float64(0.5256870470976335)), (950.0, np.float64(0.5252188259772815)), (1900.0, np.float64(0.5095298046412172)), (1910.0, np.float64(0.5064567723923248)), (1920.0, np.float64(0.5123639552228996)), (1930.0, np.float64(0.5247436776686999)), (1940.0, np.float64(0.521086636627455)), (1950.0, np.float64(0.5134994470844765)), (1960.0, np.float64(0.5022376548657967)), (1970.0, np.float64(0.4999185703827964)), (1980.0, np.float64(0.5026139130691981)), (2540.0, np.float64(0.5253442866213283)), (2550.0, np.float64(0.523943055985528)), (2560.0, np.float64(0.517426904330915)), (2570.0, np.float64(0.5072705465990327)), (2820.0, np.float64(0.5183374085065143)), (2830.0, np.float64(0.4887306446964537)), (2840.0, np.float64(0.45608193863459834)), (2850.0, np.float64(0.4621127240867665)), (2860.0, np.float64(0.4587638417724996)), (2870.0, np.float64(0.45584813612767455)), (2880.0, np.float64(0.4471440721277534)), (2890.0, np.float64(0.4396424165734649)), (2900.0, np.float64(0.41883981222208616)), (2910.0, np.float64(0.41428275979980106)), (2920.0, np.float64(0.4551412096612271)), (2930.0, np.float64(0.4590755584083965)), (2940.0, np.float64(0.4781480168362119))]
In [12]:
active_sites = [44, 66, 104, 166]  

aa_high = [int(pos/2) for pos, _ in high_windows]
aa_low  = [int(pos/2) for pos, _ in low_windows]

print("Overlap with active sites (high π):",
      set(aa_high) & set(active_sites))
print("Overlap with active sites (low π):",
      set(aa_low)  & set(active_sites))
Overlap with active sites (high π): set()
Overlap with active sites (low π): set()
In [13]:
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
from Bio import AlignIO

alignment   = AlignIO.read("aligned_sequences.aln", "fasta")
L           = alignment.get_alignment_length()
window_size = 100
step        = 10
windows     = np.arange(0, L-window_size+1, step)
pi_window   = [
    np.mean([
        0.0 if (lambda freqs: freqs.sum()<2)( 
            freqs := np.array(
                [alignment[:, pos].count(b) 
                 for b in set(alignment[:, pos]) 
                 if b not in ("-","N")],
                float
            )
        ) else 1 - np.sum((freqs/freqs.sum())**2)
        for pos in range(start, start+window_size)
    ])
    for start in windows
]

positions = windows + window_size/2

pi_arr     = np.array(pi_window)
high_thr   = np.percentile(pi_arr, 85)
low_thr    = np.percentile(pi_arr, 15)

groups = ["high" if val>=high_thr 
          else "low" if val<=low_thr 
          else "mid" 
          for val in pi_arr]

active_sites = [70, 73, 130, 166, 234, 238]

plt.figure(figsize=(10,4))
for grp, color in zip(["high","mid","low"], ["red","grey","blue"]):
    idx = [i for i,g in enumerate(groups) if g==grp]
    plt.scatter(positions[idx], pi_arr[idx], 
                c=color, label=f"{grp} diversity", s=40)

for aa in active_sites:
    nuc_pos = aa * 3
    plt.axvline(nuc_pos, color='orange', linestyle='--', alpha=0.7)
    plt.text(nuc_pos, max(pi_arr)*1.02, f"AA{aa}", 
             rotation=90, va='bottom', color='orange')

plt.title("Sliding-Window π with High/Low Diversity & Active Sites")
plt.xlabel("Position in alignment (nt)")
plt.ylabel("Nucleotide diversity π")
plt.legend(loc="upper right")
plt.ylim(0, max(pi_arr)*1.1)
plt.grid(alpha=0.3)

plt.tight_layout()
plt.savefig("sliding_window_pi_annotated.png", dpi=300)
plt.show()
No description has been provided for this image
In [14]:
df = pd.DataFrame({
    "window_start": windows,
    "window_mid":    positions,
    "pi":            pi_arr,
    "group":         groups
})

df["aa_pos_mid"] = (df["window_mid"] / 3).round().astype(int)

df["overlaps_active"] = df["aa_pos_mid"].isin(active_sites)

df.to_csv("window_pi_functional_comparison.csv", index=False)

print("Windows that intersect with functional locations:")
print(df[df["overlaps_active"]])
Windows that intersect with functional locations:
    window_start  window_mid        pi group  aa_pos_mid  overlaps_active
16           160       210.0  0.621152  high          70             True
17           170       220.0  0.624582  high          73             True
34           340       390.0  0.500011   low         130             True
In [25]:
import numpy as np
import matplotlib.pyplot as plt
from Bio import AlignIO

# 1) Load alignment
alignment   = AlignIO.read("aligned_sequences.aln", "fasta")
L           = alignment.get_alignment_length()
window_size = 100
step        = 10
starts      = np.arange(0, L - window_size + 1, step)

# 2) Compute sliding‐window π
def pi_window_vals(aln, starts, w):
    vals = []
    for s in starts:
        cols = [aln[:, i] for i in range(s, s + w)]
        pi_sites = []
        for col in cols:
            freqs = np.array(
                [col.count(b) for b in set(col) if b not in ("-", "N")],
                float
            )
            pi_sites.append(0.0 if freqs.sum() < 2 else 1 - np.sum((freqs/freqs.sum())**2))
        vals.append(np.mean(pi_sites))
    return np.array(vals)

pi_vals   = pi_window_vals(alignment, starts, window_size)
positions = starts + window_size/2

# 3) Categorize diversity levels
high_thr = np.percentile(pi_vals, 85)
low_thr  = np.percentile(pi_vals, 15)

colors = np.where(pi_vals >= high_thr, "red",
         np.where(pi_vals <= low_thr,  "navy", "olive"))

# 4) Active‐site mapping (AA positions)
active_sites_aa = [44, 66, 104, 130, 166, 237, 238]
active_sites_nt = [aa * 3 for aa in active_sites_aa]

# 5) Plotting
fig, ax = plt.subplots(figsize=(16, 6), dpi=300)
sc = ax.scatter(positions, pi_vals, c=colors, s=60, alpha=0.8)

# annotate top 5 peaks
top5 = np.argsort(pi_vals)[-5:]
for idx in top5:
    ax.annotate(f"{pi_vals[idx]:.3f}",
                (positions[idx], pi_vals[idx]),
                textcoords="offset points", xytext=(0, 10),
                ha="center", fontsize= 10, color="darkred")

# draw active‐site lines
for aa, nt in zip(active_sites_aa, active_sites_nt):
    ax.axvline(nt, color="orange", linestyle="--", linewidth=1)
    ax.text(nt, ax.get_ylim()[1]*1.02, f"AA{aa}",
            rotation=90, va="bottom", ha="center",
            fontsize=20, color="orange")

# formatting
ax.set_title("Sliding‐Window π Across TEM-1 (w=100, step=10)", fontsize=16)
ax.set_xlabel("Alignment position (nt)", fontsize=20)
ax.set_ylabel("Nucleotide diversity π", fontsize=20)
ax.set_xlim(0, L)
ax.set_ylim(0, pi_vals.max()*1.15)
ax.grid(which="major", linestyle="--", alpha=0.4)
ax.grid(which="minor", linestyle=":",  alpha=0.2)
ax.minorticks_on()

# custom legend
from matplotlib.lines import Line2D
legend_elements = [
    Line2D([0], [0], marker='o', color='w', label='High π',   markerfacecolor='red',   markersize=8),
    Line2D([0], [0], marker='o', color='w', label='Mid π',    markerfacecolor='olive',  markersize=8),
    Line2D([0], [0], marker='o', color='w', label='Low π',    markerfacecolor='navy',  markersize=8),
    Line2D([0], [0], linestyle='--', color='orange', label='Active sites')
]
ax.legend(handles=legend_elements, loc="upper right", fontsize=15)

plt.tight_layout()
# save high-res image
fig.savefig("detailed_sliding_window_pi.png", dpi=300)
plt.show()
No description has been provided for this image
In [28]:
!pip install nglview biopython
Requirement already satisfied: nglview in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (3.1.4)
Requirement already satisfied: biopython in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (1.85)
Requirement already satisfied: ipywidgets>=8 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from nglview) (8.1.7)
Requirement already satisfied: notebook>=7 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from nglview) (7.4.4)
Requirement already satisfied: jupyterlab>=3 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from nglview) (4.4.4)
Requirement already satisfied: jupyterlab_widgets in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from nglview) (3.0.15)
Requirement already satisfied: numpy in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from nglview) (2.2.6)
Requirement already satisfied: comm>=0.1.3 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from ipywidgets>=8->nglview) (0.2.2)
Requirement already satisfied: ipython>=6.1.0 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from ipywidgets>=8->nglview) (9.4.0)
Requirement already satisfied: traitlets>=4.3.1 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from ipywidgets>=8->nglview) (5.14.3)
Requirement already satisfied: widgetsnbextension~=4.0.14 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from ipywidgets>=8->nglview) (4.0.14)
Requirement already satisfied: colorama in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from ipython>=6.1.0->ipywidgets>=8->nglview) (0.4.6)
Requirement already satisfied: decorator in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from ipython>=6.1.0->ipywidgets>=8->nglview) (5.2.1)
Requirement already satisfied: ipython-pygments-lexers in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from ipython>=6.1.0->ipywidgets>=8->nglview) (1.1.1)
Requirement already satisfied: jedi>=0.16 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from ipython>=6.1.0->ipywidgets>=8->nglview) (0.19.2)
Requirement already satisfied: matplotlib-inline in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from ipython>=6.1.0->ipywidgets>=8->nglview) (0.1.7)
Requirement already satisfied: prompt_toolkit<3.1.0,>=3.0.41 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from ipython>=6.1.0->ipywidgets>=8->nglview) (3.0.51)
Requirement already satisfied: pygments>=2.4.0 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from ipython>=6.1.0->ipywidgets>=8->nglview) (2.19.2)
Requirement already satisfied: stack_data in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from ipython>=6.1.0->ipywidgets>=8->nglview) (0.6.3)
Requirement already satisfied: wcwidth in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from prompt_toolkit<3.1.0,>=3.0.41->ipython>=6.1.0->ipywidgets>=8->nglview) (0.2.13)
Requirement already satisfied: parso<0.9.0,>=0.8.4 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jedi>=0.16->ipython>=6.1.0->ipywidgets>=8->nglview) (0.8.4)
Requirement already satisfied: async-lru>=1.0.0 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jupyterlab>=3->nglview) (2.0.5)
Requirement already satisfied: httpx>=0.25.0 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jupyterlab>=3->nglview) (0.28.1)
Requirement already satisfied: ipykernel>=6.5.0 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jupyterlab>=3->nglview) (6.29.5)
Requirement already satisfied: jinja2>=3.0.3 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jupyterlab>=3->nglview) (3.1.6)
Requirement already satisfied: jupyter-core in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jupyterlab>=3->nglview) (5.8.1)
Requirement already satisfied: jupyter-lsp>=2.0.0 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jupyterlab>=3->nglview) (2.2.6)
Requirement already satisfied: jupyter-server<3,>=2.4.0 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jupyterlab>=3->nglview) (2.16.0)
Requirement already satisfied: jupyterlab-server<3,>=2.27.1 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jupyterlab>=3->nglview) (2.27.3)
Requirement already satisfied: notebook-shim>=0.2 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jupyterlab>=3->nglview) (0.2.4)
Requirement already satisfied: packaging in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jupyterlab>=3->nglview) (25.0)
Requirement already satisfied: setuptools>=41.1.0 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jupyterlab>=3->nglview) (80.9.0)
Requirement already satisfied: tornado>=6.2.0 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jupyterlab>=3->nglview) (6.5.1)
Requirement already satisfied: anyio>=3.1.0 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jupyter-server<3,>=2.4.0->jupyterlab>=3->nglview) (4.9.0)
Requirement already satisfied: argon2-cffi>=21.1 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jupyter-server<3,>=2.4.0->jupyterlab>=3->nglview) (25.1.0)
Requirement already satisfied: jupyter-client>=7.4.4 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jupyter-server<3,>=2.4.0->jupyterlab>=3->nglview) (8.6.3)
Requirement already satisfied: jupyter-events>=0.11.0 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jupyter-server<3,>=2.4.0->jupyterlab>=3->nglview) (0.12.0)
Requirement already satisfied: jupyter-server-terminals>=0.4.4 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jupyter-server<3,>=2.4.0->jupyterlab>=3->nglview) (0.5.3)
Requirement already satisfied: nbconvert>=6.4.4 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jupyter-server<3,>=2.4.0->jupyterlab>=3->nglview) (7.16.6)
Requirement already satisfied: nbformat>=5.3.0 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jupyter-server<3,>=2.4.0->jupyterlab>=3->nglview) (5.10.4)
Requirement already satisfied: overrides>=5.0 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jupyter-server<3,>=2.4.0->jupyterlab>=3->nglview) (7.7.0)
Requirement already satisfied: prometheus-client>=0.9 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jupyter-server<3,>=2.4.0->jupyterlab>=3->nglview) (0.22.1)
Requirement already satisfied: pywinpty>=2.0.1 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jupyter-server<3,>=2.4.0->jupyterlab>=3->nglview) (2.0.15)
Requirement already satisfied: pyzmq>=24 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jupyter-server<3,>=2.4.0->jupyterlab>=3->nglview) (27.0.0)
Requirement already satisfied: send2trash>=1.8.2 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jupyter-server<3,>=2.4.0->jupyterlab>=3->nglview) (1.8.3)
Requirement already satisfied: terminado>=0.8.3 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jupyter-server<3,>=2.4.0->jupyterlab>=3->nglview) (0.18.1)
Requirement already satisfied: websocket-client>=1.7 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jupyter-server<3,>=2.4.0->jupyterlab>=3->nglview) (1.8.0)
Requirement already satisfied: babel>=2.10 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jupyterlab-server<3,>=2.27.1->jupyterlab>=3->nglview) (2.17.0)
Requirement already satisfied: json5>=0.9.0 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jupyterlab-server<3,>=2.27.1->jupyterlab>=3->nglview) (0.12.0)
Requirement already satisfied: jsonschema>=4.18.0 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jupyterlab-server<3,>=2.27.1->jupyterlab>=3->nglview) (4.25.0)
Requirement already satisfied: requests>=2.31 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jupyterlab-server<3,>=2.27.1->jupyterlab>=3->nglview) (2.32.4)
Requirement already satisfied: idna>=2.8 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from anyio>=3.1.0->jupyter-server<3,>=2.4.0->jupyterlab>=3->nglview) (3.10)
Requirement already satisfied: sniffio>=1.1 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from anyio>=3.1.0->jupyter-server<3,>=2.4.0->jupyterlab>=3->nglview) (1.3.1)
Requirement already satisfied: argon2-cffi-bindings in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from argon2-cffi>=21.1->jupyter-server<3,>=2.4.0->jupyterlab>=3->nglview) (21.2.0)
Requirement already satisfied: certifi in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from httpx>=0.25.0->jupyterlab>=3->nglview) (2025.7.14)
Requirement already satisfied: httpcore==1.* in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from httpx>=0.25.0->jupyterlab>=3->nglview) (1.0.9)
Requirement already satisfied: h11>=0.16 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from httpcore==1.*->httpx>=0.25.0->jupyterlab>=3->nglview) (0.16.0)
Requirement already satisfied: debugpy>=1.6.5 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from ipykernel>=6.5.0->jupyterlab>=3->nglview) (1.8.15)
Requirement already satisfied: nest-asyncio in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from ipykernel>=6.5.0->jupyterlab>=3->nglview) (1.6.0)
Requirement already satisfied: psutil in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from ipykernel>=6.5.0->jupyterlab>=3->nglview) (7.0.0)
Requirement already satisfied: MarkupSafe>=2.0 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jinja2>=3.0.3->jupyterlab>=3->nglview) (3.0.2)
Requirement already satisfied: attrs>=22.2.0 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jsonschema>=4.18.0->jupyterlab-server<3,>=2.27.1->jupyterlab>=3->nglview) (25.3.0)
Requirement already satisfied: jsonschema-specifications>=2023.03.6 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jsonschema>=4.18.0->jupyterlab-server<3,>=2.27.1->jupyterlab>=3->nglview) (2025.4.1)
Requirement already satisfied: referencing>=0.28.4 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jsonschema>=4.18.0->jupyterlab-server<3,>=2.27.1->jupyterlab>=3->nglview) (0.36.2)
Requirement already satisfied: rpds-py>=0.7.1 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jsonschema>=4.18.0->jupyterlab-server<3,>=2.27.1->jupyterlab>=3->nglview) (0.26.0)
Requirement already satisfied: python-dateutil>=2.8.2 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jupyter-client>=7.4.4->jupyter-server<3,>=2.4.0->jupyterlab>=3->nglview) (2.9.0.post0)
Requirement already satisfied: platformdirs>=2.5 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jupyter-core->jupyterlab>=3->nglview) (4.3.8)
Requirement already satisfied: pywin32>=300 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jupyter-core->jupyterlab>=3->nglview) (311)
Requirement already satisfied: python-json-logger>=2.0.4 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jupyter-events>=0.11.0->jupyter-server<3,>=2.4.0->jupyterlab>=3->nglview) (3.3.0)
Requirement already satisfied: pyyaml>=5.3 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jupyter-events>=0.11.0->jupyter-server<3,>=2.4.0->jupyterlab>=3->nglview) (6.0.2)
Requirement already satisfied: rfc3339-validator in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jupyter-events>=0.11.0->jupyter-server<3,>=2.4.0->jupyterlab>=3->nglview) (0.1.4)
Requirement already satisfied: rfc3986-validator>=0.1.1 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jupyter-events>=0.11.0->jupyter-server<3,>=2.4.0->jupyterlab>=3->nglview) (0.1.1)
Requirement already satisfied: fqdn in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jsonschema[format-nongpl]>=4.18.0->jupyter-events>=0.11.0->jupyter-server<3,>=2.4.0->jupyterlab>=3->nglview) (1.5.1)
Requirement already satisfied: isoduration in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jsonschema[format-nongpl]>=4.18.0->jupyter-events>=0.11.0->jupyter-server<3,>=2.4.0->jupyterlab>=3->nglview) (20.11.0)
Requirement already satisfied: jsonpointer>1.13 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jsonschema[format-nongpl]>=4.18.0->jupyter-events>=0.11.0->jupyter-server<3,>=2.4.0->jupyterlab>=3->nglview) (3.0.0)
Requirement already satisfied: rfc3987-syntax>=1.1.0 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jsonschema[format-nongpl]>=4.18.0->jupyter-events>=0.11.0->jupyter-server<3,>=2.4.0->jupyterlab>=3->nglview) (1.1.0)
Requirement already satisfied: uri-template in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jsonschema[format-nongpl]>=4.18.0->jupyter-events>=0.11.0->jupyter-server<3,>=2.4.0->jupyterlab>=3->nglview) (1.3.0)
Requirement already satisfied: webcolors>=24.6.0 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jsonschema[format-nongpl]>=4.18.0->jupyter-events>=0.11.0->jupyter-server<3,>=2.4.0->jupyterlab>=3->nglview) (24.11.1)
Requirement already satisfied: beautifulsoup4 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from nbconvert>=6.4.4->jupyter-server<3,>=2.4.0->jupyterlab>=3->nglview) (4.13.4)
Requirement already satisfied: bleach!=5.0.0 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from bleach[css]!=5.0.0->nbconvert>=6.4.4->jupyter-server<3,>=2.4.0->jupyterlab>=3->nglview) (6.2.0)
Requirement already satisfied: defusedxml in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from nbconvert>=6.4.4->jupyter-server<3,>=2.4.0->jupyterlab>=3->nglview) (0.7.1)
Requirement already satisfied: jupyterlab-pygments in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from nbconvert>=6.4.4->jupyter-server<3,>=2.4.0->jupyterlab>=3->nglview) (0.3.0)
Requirement already satisfied: mistune<4,>=2.0.3 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from nbconvert>=6.4.4->jupyter-server<3,>=2.4.0->jupyterlab>=3->nglview) (3.1.3)
Requirement already satisfied: nbclient>=0.5.0 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from nbconvert>=6.4.4->jupyter-server<3,>=2.4.0->jupyterlab>=3->nglview) (0.10.2)
Requirement already satisfied: pandocfilters>=1.4.1 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from nbconvert>=6.4.4->jupyter-server<3,>=2.4.0->jupyterlab>=3->nglview) (1.5.1)
Requirement already satisfied: webencodings in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from bleach!=5.0.0->bleach[css]!=5.0.0->nbconvert>=6.4.4->jupyter-server<3,>=2.4.0->jupyterlab>=3->nglview) (0.5.1)
Requirement already satisfied: tinycss2<1.5,>=1.1.0 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from bleach[css]!=5.0.0->nbconvert>=6.4.4->jupyter-server<3,>=2.4.0->jupyterlab>=3->nglview) (1.4.0)
Requirement already satisfied: fastjsonschema>=2.15 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from nbformat>=5.3.0->jupyter-server<3,>=2.4.0->jupyterlab>=3->nglview) (2.21.1)
Requirement already satisfied: six>=1.5 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from python-dateutil>=2.8.2->jupyter-client>=7.4.4->jupyter-server<3,>=2.4.0->jupyterlab>=3->nglview) (1.17.0)
Requirement already satisfied: charset_normalizer<4,>=2 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from requests>=2.31->jupyterlab-server<3,>=2.27.1->jupyterlab>=3->nglview) (3.4.2)
Requirement already satisfied: urllib3<3,>=1.21.1 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from requests>=2.31->jupyterlab-server<3,>=2.27.1->jupyterlab>=3->nglview) (2.5.0)
Requirement already satisfied: lark>=1.2.2 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from rfc3987-syntax>=1.1.0->jsonschema[format-nongpl]>=4.18.0->jupyter-events>=0.11.0->jupyter-server<3,>=2.4.0->jupyterlab>=3->nglview) (1.2.2)
Requirement already satisfied: cffi>=1.0.1 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from argon2-cffi-bindings->argon2-cffi>=21.1->jupyter-server<3,>=2.4.0->jupyterlab>=3->nglview) (1.17.1)
Requirement already satisfied: pycparser in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from cffi>=1.0.1->argon2-cffi-bindings->argon2-cffi>=21.1->jupyter-server<3,>=2.4.0->jupyterlab>=3->nglview) (2.22)
Requirement already satisfied: soupsieve>1.2 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from beautifulsoup4->nbconvert>=6.4.4->jupyter-server<3,>=2.4.0->jupyterlab>=3->nglview) (2.7)
Requirement already satisfied: typing-extensions>=4.0.0 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from beautifulsoup4->nbconvert>=6.4.4->jupyter-server<3,>=2.4.0->jupyterlab>=3->nglview) (4.14.1)
Requirement already satisfied: arrow>=0.15.0 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from isoduration->jsonschema[format-nongpl]>=4.18.0->jupyter-events>=0.11.0->jupyter-server<3,>=2.4.0->jupyterlab>=3->nglview) (1.3.0)
Requirement already satisfied: types-python-dateutil>=2.8.10 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from arrow>=0.15.0->isoduration->jsonschema[format-nongpl]>=4.18.0->jupyter-events>=0.11.0->jupyter-server<3,>=2.4.0->jupyterlab>=3->nglview) (2.9.0.20250708)
Requirement already satisfied: executing>=1.2.0 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from stack_data->ipython>=6.1.0->ipywidgets>=8->nglview) (2.2.0)
Requirement already satisfied: asttokens>=2.1.0 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from stack_data->ipython>=6.1.0->ipywidgets>=8->nglview) (3.0.0)
Requirement already satisfied: pure-eval in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from stack_data->ipython>=6.1.0->ipywidgets>=8->nglview) (0.2.3)
WARNING: Ignoring invalid distribution ~umpy (D:\Osama\biotec\Bioinformatics\mutation_structural_analysis_ncbi\venv\Lib\site-packages)
WARNING: Ignoring invalid distribution ~umpy (D:\Osama\biotec\Bioinformatics\mutation_structural_analysis_ncbi\venv\Lib\site-packages)
WARNING: Ignoring invalid distribution ~umpy (D:\Osama\biotec\Bioinformatics\mutation_structural_analysis_ncbi\venv\Lib\site-packages)
In [29]:
!jupyter-nbextension enable nglview --py --sys-prefix
'jupyter-nbextension' is not recognized as an internal or external command,
operable program or batch file.
In [30]:
!jupyter labextension install nglview-js-widgets
(Deprecated) Installing extensions with the jupyter labextension install command is now deprecated and will be removed in a future major version of JupyterLab.

Users should manage prebuilt extensions with package managers like pip and conda, and extension authors are encouraged to distribute their extensions as prebuilt packages 
D:\Osama\biotec\Bioinformatics\mutation_structural_analysis_ncbi\venv\Lib\site-packages\jupyterlab\debuglog.py:54: UserWarning: An error occurred.
  warnings.warn("An error occurred.")
D:\Osama\biotec\Bioinformatics\mutation_structural_analysis_ncbi\venv\Lib\site-packages\jupyterlab\debuglog.py:55: UserWarning: ValueError: Please install Node.js and npm before continuing installation. You may be able to install Node.js from your package manager, from conda, or directly from the Node.js website (https://nodejs.org).
  warnings.warn(msg[-1].strip())
D:\Osama\biotec\Bioinformatics\mutation_structural_analysis_ncbi\venv\Lib\site-packages\jupyterlab\debuglog.py:56: UserWarning: See the log file for details: C:\Users\osama\AppData\Local\Temp\jupyterlab-debug-ylwdwbx8.log
  warnings.warn(f"See the log file for details: {log_path!s}")
In [31]:
%pip install nglview biopython ipywidgets
Requirement already satisfied: nglview in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (3.1.4)
Requirement already satisfied: biopython in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (1.85)
Requirement already satisfied: ipywidgets in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (8.1.7)
Requirement already satisfied: notebook>=7 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from nglview) (7.4.4)
Requirement already satisfied: jupyterlab>=3 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from nglview) (4.4.4)
Requirement already satisfied: jupyterlab_widgets in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from nglview) (3.0.15)
Requirement already satisfied: numpy in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from nglview) (2.2.6)
Requirement already satisfied: comm>=0.1.3 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from ipywidgets) (0.2.2)
Requirement already satisfied: ipython>=6.1.0 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from ipywidgets) (9.4.0)
Requirement already satisfied: traitlets>=4.3.1 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from ipywidgets) (5.14.3)
Requirement already satisfied: widgetsnbextension~=4.0.14 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from ipywidgets) (4.0.14)
Requirement already satisfied: colorama in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from ipython>=6.1.0->ipywidgets) (0.4.6)
Requirement already satisfied: decorator in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from ipython>=6.1.0->ipywidgets) (5.2.1)
Requirement already satisfied: ipython-pygments-lexers in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from ipython>=6.1.0->ipywidgets) (1.1.1)
Requirement already satisfied: jedi>=0.16 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from ipython>=6.1.0->ipywidgets) (0.19.2)
Requirement already satisfied: matplotlib-inline in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from ipython>=6.1.0->ipywidgets) (0.1.7)
Requirement already satisfied: prompt_toolkit<3.1.0,>=3.0.41 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from ipython>=6.1.0->ipywidgets) (3.0.51)
Requirement already satisfied: pygments>=2.4.0 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from ipython>=6.1.0->ipywidgets) (2.19.2)
Requirement already satisfied: stack_data in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from ipython>=6.1.0->ipywidgets) (0.6.3)
Requirement already satisfied: wcwidth in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from prompt_toolkit<3.1.0,>=3.0.41->ipython>=6.1.0->ipywidgets) (0.2.13)
Requirement already satisfied: parso<0.9.0,>=0.8.4 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jedi>=0.16->ipython>=6.1.0->ipywidgets) (0.8.4)
Requirement already satisfied: async-lru>=1.0.0 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jupyterlab>=3->nglview) (2.0.5)
Requirement already satisfied: httpx>=0.25.0 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jupyterlab>=3->nglview) (0.28.1)
Requirement already satisfied: ipykernel>=6.5.0 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jupyterlab>=3->nglview) (6.29.5)
Requirement already satisfied: jinja2>=3.0.3 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jupyterlab>=3->nglview) (3.1.6)
Requirement already satisfied: jupyter-core in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jupyterlab>=3->nglview) (5.8.1)
Requirement already satisfied: jupyter-lsp>=2.0.0 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jupyterlab>=3->nglview) (2.2.6)
Requirement already satisfied: jupyter-server<3,>=2.4.0 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jupyterlab>=3->nglview) (2.16.0)
Requirement already satisfied: jupyterlab-server<3,>=2.27.1 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jupyterlab>=3->nglview) (2.27.3)
Requirement already satisfied: notebook-shim>=0.2 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jupyterlab>=3->nglview) (0.2.4)
Requirement already satisfied: packaging in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jupyterlab>=3->nglview) (25.0)
Requirement already satisfied: setuptools>=41.1.0 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jupyterlab>=3->nglview) (80.9.0)
Requirement already satisfied: tornado>=6.2.0 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jupyterlab>=3->nglview) (6.5.1)
Requirement already satisfied: anyio>=3.1.0 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jupyter-server<3,>=2.4.0->jupyterlab>=3->nglview) (4.9.0)
Requirement already satisfied: argon2-cffi>=21.1 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jupyter-server<3,>=2.4.0->jupyterlab>=3->nglview) (25.1.0)
Requirement already satisfied: jupyter-client>=7.4.4 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jupyter-server<3,>=2.4.0->jupyterlab>=3->nglview) (8.6.3)
Requirement already satisfied: jupyter-events>=0.11.0 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jupyter-server<3,>=2.4.0->jupyterlab>=3->nglview) (0.12.0)
Requirement already satisfied: jupyter-server-terminals>=0.4.4 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jupyter-server<3,>=2.4.0->jupyterlab>=3->nglview) (0.5.3)
Requirement already satisfied: nbconvert>=6.4.4 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jupyter-server<3,>=2.4.0->jupyterlab>=3->nglview) (7.16.6)
Requirement already satisfied: nbformat>=5.3.0 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jupyter-server<3,>=2.4.0->jupyterlab>=3->nglview) (5.10.4)
Requirement already satisfied: overrides>=5.0 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jupyter-server<3,>=2.4.0->jupyterlab>=3->nglview) (7.7.0)
Requirement already satisfied: prometheus-client>=0.9 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jupyter-server<3,>=2.4.0->jupyterlab>=3->nglview) (0.22.1)
Requirement already satisfied: pywinpty>=2.0.1 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jupyter-server<3,>=2.4.0->jupyterlab>=3->nglview) (2.0.15)
Requirement already satisfied: pyzmq>=24 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jupyter-server<3,>=2.4.0->jupyterlab>=3->nglview) (27.0.0)
Requirement already satisfied: send2trash>=1.8.2 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jupyter-server<3,>=2.4.0->jupyterlab>=3->nglview) (1.8.3)
Requirement already satisfied: terminado>=0.8.3 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jupyter-server<3,>=2.4.0->jupyterlab>=3->nglview) (0.18.1)
Requirement already satisfied: websocket-client>=1.7 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jupyter-server<3,>=2.4.0->jupyterlab>=3->nglview) (1.8.0)
Requirement already satisfied: babel>=2.10 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jupyterlab-server<3,>=2.27.1->jupyterlab>=3->nglview) (2.17.0)
Requirement already satisfied: json5>=0.9.0 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jupyterlab-server<3,>=2.27.1->jupyterlab>=3->nglview) (0.12.0)
Requirement already satisfied: jsonschema>=4.18.0 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jupyterlab-server<3,>=2.27.1->jupyterlab>=3->nglview) (4.25.0)
Requirement already satisfied: requests>=2.31 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jupyterlab-server<3,>=2.27.1->jupyterlab>=3->nglview) (2.32.4)
Requirement already satisfied: idna>=2.8 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from anyio>=3.1.0->jupyter-server<3,>=2.4.0->jupyterlab>=3->nglview) (3.10)
Requirement already satisfied: sniffio>=1.1 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from anyio>=3.1.0->jupyter-server<3,>=2.4.0->jupyterlab>=3->nglview) (1.3.1)
Requirement already satisfied: argon2-cffi-bindings in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from argon2-cffi>=21.1->jupyter-server<3,>=2.4.0->jupyterlab>=3->nglview) (21.2.0)
Requirement already satisfied: certifi in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from httpx>=0.25.0->jupyterlab>=3->nglview) (2025.7.14)
Requirement already satisfied: httpcore==1.* in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from httpx>=0.25.0->jupyterlab>=3->nglview) (1.0.9)
Requirement already satisfied: h11>=0.16 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from httpcore==1.*->httpx>=0.25.0->jupyterlab>=3->nglview) (0.16.0)
Requirement already satisfied: debugpy>=1.6.5 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from ipykernel>=6.5.0->jupyterlab>=3->nglview) (1.8.15)
Requirement already satisfied: nest-asyncio in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from ipykernel>=6.5.0->jupyterlab>=3->nglview) (1.6.0)
Requirement already satisfied: psutil in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from ipykernel>=6.5.0->jupyterlab>=3->nglview) (7.0.0)
Requirement already satisfied: MarkupSafe>=2.0 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jinja2>=3.0.3->jupyterlab>=3->nglview) (3.0.2)
Requirement already satisfied: attrs>=22.2.0 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jsonschema>=4.18.0->jupyterlab-server<3,>=2.27.1->jupyterlab>=3->nglview) (25.3.0)
Requirement already satisfied: jsonschema-specifications>=2023.03.6 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jsonschema>=4.18.0->jupyterlab-server<3,>=2.27.1->jupyterlab>=3->nglview) (2025.4.1)
Requirement already satisfied: referencing>=0.28.4 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jsonschema>=4.18.0->jupyterlab-server<3,>=2.27.1->jupyterlab>=3->nglview) (0.36.2)
Requirement already satisfied: rpds-py>=0.7.1 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jsonschema>=4.18.0->jupyterlab-server<3,>=2.27.1->jupyterlab>=3->nglview) (0.26.0)
Requirement already satisfied: python-dateutil>=2.8.2 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jupyter-client>=7.4.4->jupyter-server<3,>=2.4.0->jupyterlab>=3->nglview) (2.9.0.post0)
Requirement already satisfied: platformdirs>=2.5 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jupyter-core->jupyterlab>=3->nglview) (4.3.8)
Requirement already satisfied: pywin32>=300 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jupyter-core->jupyterlab>=3->nglview) (311)
Requirement already satisfied: python-json-logger>=2.0.4 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jupyter-events>=0.11.0->jupyter-server<3,>=2.4.0->jupyterlab>=3->nglview) (3.3.0)
Requirement already satisfied: pyyaml>=5.3 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jupyter-events>=0.11.0->jupyter-server<3,>=2.4.0->jupyterlab>=3->nglview) (6.0.2)
Requirement already satisfied: rfc3339-validator in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jupyter-events>=0.11.0->jupyter-server<3,>=2.4.0->jupyterlab>=3->nglview) (0.1.4)
Requirement already satisfied: rfc3986-validator>=0.1.1 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jupyter-events>=0.11.0->jupyter-server<3,>=2.4.0->jupyterlab>=3->nglview) (0.1.1)
Requirement already satisfied: fqdn in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jsonschema[format-nongpl]>=4.18.0->jupyter-events>=0.11.0->jupyter-server<3,>=2.4.0->jupyterlab>=3->nglview) (1.5.1)
Requirement already satisfied: isoduration in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jsonschema[format-nongpl]>=4.18.0->jupyter-events>=0.11.0->jupyter-server<3,>=2.4.0->jupyterlab>=3->nglview) (20.11.0)
Requirement already satisfied: jsonpointer>1.13 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jsonschema[format-nongpl]>=4.18.0->jupyter-events>=0.11.0->jupyter-server<3,>=2.4.0->jupyterlab>=3->nglview) (3.0.0)
Requirement already satisfied: rfc3987-syntax>=1.1.0 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jsonschema[format-nongpl]>=4.18.0->jupyter-events>=0.11.0->jupyter-server<3,>=2.4.0->jupyterlab>=3->nglview) (1.1.0)
Requirement already satisfied: uri-template in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jsonschema[format-nongpl]>=4.18.0->jupyter-events>=0.11.0->jupyter-server<3,>=2.4.0->jupyterlab>=3->nglview) (1.3.0)
Requirement already satisfied: webcolors>=24.6.0 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from jsonschema[format-nongpl]>=4.18.0->jupyter-events>=0.11.0->jupyter-server<3,>=2.4.0->jupyterlab>=3->nglview) (24.11.1)
Requirement already satisfied: beautifulsoup4 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from nbconvert>=6.4.4->jupyter-server<3,>=2.4.0->jupyterlab>=3->nglview) (4.13.4)
Requirement already satisfied: bleach!=5.0.0 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from bleach[css]!=5.0.0->nbconvert>=6.4.4->jupyter-server<3,>=2.4.0->jupyterlab>=3->nglview) (6.2.0)
Requirement already satisfied: defusedxml in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from nbconvert>=6.4.4->jupyter-server<3,>=2.4.0->jupyterlab>=3->nglview) (0.7.1)
Requirement already satisfied: jupyterlab-pygments in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from nbconvert>=6.4.4->jupyter-server<3,>=2.4.0->jupyterlab>=3->nglview) (0.3.0)
Requirement already satisfied: mistune<4,>=2.0.3 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from nbconvert>=6.4.4->jupyter-server<3,>=2.4.0->jupyterlab>=3->nglview) (3.1.3)
Requirement already satisfied: nbclient>=0.5.0 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from nbconvert>=6.4.4->jupyter-server<3,>=2.4.0->jupyterlab>=3->nglview) (0.10.2)
Requirement already satisfied: pandocfilters>=1.4.1 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from nbconvert>=6.4.4->jupyter-server<3,>=2.4.0->jupyterlab>=3->nglview) (1.5.1)
Requirement already satisfied: webencodings in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from bleach!=5.0.0->bleach[css]!=5.0.0->nbconvert>=6.4.4->jupyter-server<3,>=2.4.0->jupyterlab>=3->nglview) (0.5.1)
Requirement already satisfied: tinycss2<1.5,>=1.1.0 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from bleach[css]!=5.0.0->nbconvert>=6.4.4->jupyter-server<3,>=2.4.0->jupyterlab>=3->nglview) (1.4.0)
Requirement already satisfied: fastjsonschema>=2.15 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from nbformat>=5.3.0->jupyter-server<3,>=2.4.0->jupyterlab>=3->nglview) (2.21.1)
Requirement already satisfied: six>=1.5 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from python-dateutil>=2.8.2->jupyter-client>=7.4.4->jupyter-server<3,>=2.4.0->jupyterlab>=3->nglview) (1.17.0)
Requirement already satisfied: charset_normalizer<4,>=2 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from requests>=2.31->jupyterlab-server<3,>=2.27.1->jupyterlab>=3->nglview) (3.4.2)
Requirement already satisfied: urllib3<3,>=1.21.1 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from requests>=2.31->jupyterlab-server<3,>=2.27.1->jupyterlab>=3->nglview) (2.5.0)
Requirement already satisfied: lark>=1.2.2 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from rfc3987-syntax>=1.1.0->jsonschema[format-nongpl]>=4.18.0->jupyter-events>=0.11.0->jupyter-server<3,>=2.4.0->jupyterlab>=3->nglview) (1.2.2)
Requirement already satisfied: cffi>=1.0.1 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from argon2-cffi-bindings->argon2-cffi>=21.1->jupyter-server<3,>=2.4.0->jupyterlab>=3->nglview) (1.17.1)
Requirement already satisfied: pycparser in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from cffi>=1.0.1->argon2-cffi-bindings->argon2-cffi>=21.1->jupyter-server<3,>=2.4.0->jupyterlab>=3->nglview) (2.22)
Requirement already satisfied: soupsieve>1.2 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from beautifulsoup4->nbconvert>=6.4.4->jupyter-server<3,>=2.4.0->jupyterlab>=3->nglview) (2.7)
Requirement already satisfied: typing-extensions>=4.0.0 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from beautifulsoup4->nbconvert>=6.4.4->jupyter-server<3,>=2.4.0->jupyterlab>=3->nglview) (4.14.1)
Requirement already satisfied: arrow>=0.15.0 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from isoduration->jsonschema[format-nongpl]>=4.18.0->jupyter-events>=0.11.0->jupyter-server<3,>=2.4.0->jupyterlab>=3->nglview) (1.3.0)
Requirement already satisfied: types-python-dateutil>=2.8.10 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from arrow>=0.15.0->isoduration->jsonschema[format-nongpl]>=4.18.0->jupyter-events>=0.11.0->jupyter-server<3,>=2.4.0->jupyterlab>=3->nglview) (2.9.0.20250708)
Requirement already satisfied: executing>=1.2.0 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from stack_data->ipython>=6.1.0->ipywidgets) (2.2.0)
Requirement already satisfied: asttokens>=2.1.0 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from stack_data->ipython>=6.1.0->ipywidgets) (3.0.0)
Requirement already satisfied: pure-eval in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from stack_data->ipython>=6.1.0->ipywidgets) (0.2.3)
Note: you may need to restart the kernel to use updated packages.
WARNING: Ignoring invalid distribution ~umpy (D:\Osama\biotec\Bioinformatics\mutation_structural_analysis_ncbi\venv\Lib\site-packages)
WARNING: Ignoring invalid distribution ~umpy (D:\Osama\biotec\Bioinformatics\mutation_structural_analysis_ncbi\venv\Lib\site-packages)
WARNING: Ignoring invalid distribution ~umpy (D:\Osama\biotec\Bioinformatics\mutation_structural_analysis_ncbi\venv\Lib\site-packages)
In [1]:
import nglview as nv
print("nglview version:", nv.__version__)

nglview version: 3.1.4
D:\Osama\biotec\Bioinformatics\mutation_structural_analysis_ncbi\venv\Lib\site-packages\nglview\__init__.py:12: UserWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html. The pkg_resources package is slated for removal as early as 2025-11-30. Refrain from using this package or pin to Setuptools<81.
  import pkg_resources
In [2]:
from Bio.PDB import PDBList

pdbl = PDBList()
pdbl.retrieve_pdb_file("1ZG4", pdir=".", file_format="pdb")
Downloading PDB structure '1zg4'...
Out[2]:
'.\\pdb1zg4.ent'
In [15]:
from Bio.PDB import PDBList, PDBParser
import os

pdbl = PDBList()
pdb_path = pdbl.retrieve_pdb_file(
    "1ZG4",
    pdir=".",                    
    file_format="pdb"           
)
print("The file was downloaded to:", pdb_path)


base = os.path.basename(pdb_path)         # e.g. 'pdb1zg4.ent'
if base.startswith("pdb") and base.endswith(".ent"):
    new_name = "1zg4.pdb"
    os.rename(pdb_path, new_name)
    pdb_path = new_name
    print(" Renamed to:", pdb_path)

parser = PDBParser(QUIET=True)
structure = parser.get_structure("TEM1", pdb_path)
print(" The structure was successfully loaded from:", pdb_path)


import nglview as nv
view = nv.show_biopython(structure)
view.clear_representations()
view.add_cartoon(color="lightgrey")
view.add_ball_and_stick(selection="protein", color="grey")
view
Structure exists: '.\pdb1zg4.ent' 
The file was downloaded to: .\pdb1zg4.ent
 Renamed to: 1zg4.pdb
 The structure was successfully loaded from: 1zg4.pdb
NGLWidget()
In [34]:
critical_aas = [44, 66, 104, 130, 166, 237, 238]

for aa in critical_aas:
    view.add_ball_and_stick(
        selection=f"resi {aa} and protein",
        color="lightnavy",
        radius=1.8
    )


view.background = "black"             # أو "black"
view.parameters = {
    "clipNear": 0.1,
    "clipFar": 1000,
    "lightIntensity": 1.0
}

view.download_image(
    filename="mutations_on_structure.png",
    factor=3
)
In [35]:
import os
from IPython.display import Image, display
view
NGLWidget(background='black', n_components=1, picked={'atom1': {'index': 18, 'residueIndex': 2, 'resname': 'GL…

import os import webbrowser

1) Parameters¶

pdb_id = "1zg4" critical_residues = [44, 66, 104, 130, 166, 237, 238] file_name = "mutations_viewer.html"

2) Build the HTML content¶

html = f"""

TEM-1 Mutational 3D Viewer

TEM-1 β-lactamase Mutational Mapping

Critical residues highlighted: {', '.join(map(str, critical_residues))}

"""

3) Write the HTML to disk¶

with open(file_name, "w", encoding="utf-8") as f: f.write(html) print(f"✅ Written interactive viewer to {file_name}")

4) Open the file in the default web browser (usually Chrome)¶

path = os.path.abspath(file_name) webbrowser.open_new_tab(f"file:///{path}")

In [33]:
view.clear_representations()

view.add_cartoon(color="lightgrey")            # cartoon
view.add_ball_and_stick(color="lightnavy", sele="resi 44-50")   
view.add_ribbon(color="navy")                 # ribbon
view.add_licorice(color="green")                # licorice
view.add_line(color="gray")                     # line
view.add_point(color="black")                   # point

view.parameters = {"clipNear":0.5, "clipFar":300}
view
NGLWidget(n_components=1, picked={'atom1': {'index': 18, 'residueIndex': 2, 'resname': 'GLU', 'x': 6.738999843…
In [31]:
import os, webbrowser

# 1) PARAMETERS
pdb_id = "1zg4"
critical_residues = [44, 66, 104, 130, 166, 237, 238]
html_file = "mutations_structure.html"

# 2) BUILD THE HTML
html = f"""<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>TEM-1 β-lactamase 3D Viewer</title>
  <script src="https://cdn.jsdelivr.net/npm/ngl@latest/dist/ngl.js"></script>
  <style>
    body {{ margin:0; font-family:sans-serif; background:#f0f0f0 }}
    #header {{ padding:12px; background:#333; color:#fff }}
    #header h1 {{ margin:0; font-size:1.4em }}
    #header p {{ margin:4px 0 0; font-size:.95em }}
    #viewport {{ width:100vw; height:calc(100vh - 60px) }}
  </style>
</head>
<body>
  <div id="header">
    <h1>TEM-1 Mutational Mapping</h1>
    <p>Highlighted residues: {', '.join(map(str, critical_residues))}</p>
  </div>
  <div id="viewport"></div>
  <script>
    const stage = new NGL.Stage("viewport");
    stage.loadFile("rcsb://{pdb_id}").then(o => {{
      o.addRepresentation("cartoon", {{ color: "lightgrey" }});
      o.addRepresentation("surface", {{color:"lightblue", opacity:0.3}});
      o.addRepresentation("ball+stick", {{
        sele: "{' or '.join(':'+str(r) for r in critical_residues)}",
        color: "crimson",
        radius: 1.4
      }});
      stage.autoView();
    }});
  </script>
</body>
</html>
"""

# 3) WRITE TO DISK
with open(html_file, "w", encoding="utf-8") as f:
    f.write(html)
print("✅ Written standalone HTML to", html_file)

# 4) OPEN IN BROWSER
path = os.path.abspath(html_file)
webbrowser.open(f"file:///{path}")
✅ Written standalone HTML to mutations_structure.html
Out[31]:
True
In [47]:
from Bio import AlignIO, Phylo
from Bio.Phylo.TreeConstruction import DistanceCalculator, DistanceTreeConstructor
import matplotlib.pyplot as plt
import os

alignment_file = "aligned_sequences.aln"  
if not os.path.exists(alignment_file):
    raise FileNotFoundError(f"{alignment_file} not found in {os.getcwd()}")

alignment = AlignIO.read(alignment_file, "fasta")
calc      = DistanceCalculator("identity")
dm        = calc.get_distance(alignment)
nj_cons   = DistanceTreeConstructor()
tree      = nj_cons.nj(dm)

tree.ladderize()

fig = plt.figure(figsize=(15, 30))              
ax  = fig.add_subplot(1, 1, 1)

Phylo.draw(tree,
           axes=ax,
           do_show=False,
           show_confidence=False)


for lbl in ax.get_yticklabels():
    lbl.set_fontsize(6)
    lbl.set_horizontalalignment('left')       

ax.set_ylim(ax.get_ylim()[::-1])             
ax.xaxis.set_visible(False)                  
ax.tick_params(left=False)                    
plt.title("NJ Tree from FASTA Alignment", fontsize=10, pad=20)
plt.tight_layout()

plt.savefig("NJ_tree.png",
            dpi=300,            
            bbox_inches="tight" 
           )

plt.show()
No description has been provided for this image
In [38]:
import os

print("Current working directory:", os.getcwd())
print("Files in cwd:", os.listdir())
Current working directory: D:\Osama\biotec\Bioinformatics\mutation_structural_analysis_ncbi
Files in cwd: ['.ipynb_checkpoints', '1zg4.pdb', 'aligned_sequences.aln', 'clustal-omega-1.2.2-win64', 'detailed_sliding_window_pi.png', 'diversity_windows.csv', 'filtered_sequences.fasta', 'from Bio import Entrez, SeqIO.py', 'mutations3d.html', 'mutations3d.txt', 'mutations_on_structure (1).png', 'mutations_on_structure (2).png', 'mutations_on_structure.png', 'mutations_structure.html', 'mutations_viewer.html', 'pca_plot.png', 'pdb1zg4.ent', 'sequence_lengths.csv', 'sliding_window_pi.png', 'sliding_window_pi_annotated.png', 'snp_table.csv', 'tem.pdf', 'tem1_sequences.fasta', 'TEM_analysis.html', 'TEM_analysis.ipynb', 'TEM_analysis.ipynb2', 'umap_plot.png', 'venv', 'window_pi_functional_comparison.csv']
In [52]:
for clade in tree.find_clades():
    clade.branch_length = 2.0

# رسم
fig = plt.figure(figsize=(25, 25))
ax  = fig.add_subplot(1, 1, 1)

Phylo.draw(tree, axes=ax, do_show=False, show_confidence=False)
plt.title("Cladogram (Equal Branch Lengths)")
plt.tight_layout()
plt.savefig("tree_cladogram.png", dpi=300, bbox_inches="tight")
plt.show()
No description has been provided for this image
In [65]:
!pip install requests
Requirement already satisfied: requests in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (2.32.4)
Requirement already satisfied: charset_normalizer<4,>=2 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from requests) (3.4.2)
Requirement already satisfied: idna<4,>=2.5 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from requests) (3.10)
Requirement already satisfied: urllib3<3,>=1.21.1 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from requests) (2.5.0)
Requirement already satisfied: certifi>=2017.4.17 in d:\osama\biotec\bioinformatics\mutation_structural_analysis_ncbi\venv\lib\site-packages (from requests) (2025.7.14)
WARNING: Ignoring invalid distribution ~umpy (D:\Osama\biotec\Bioinformatics\mutation_structural_analysis_ncbi\venv\Lib\site-packages)
WARNING: Ignoring invalid distribution ~umpy (D:\Osama\biotec\Bioinformatics\mutation_structural_analysis_ncbi\venv\Lib\site-packages)
WARNING: Ignoring invalid distribution ~umpy (D:\Osama\biotec\Bioinformatics\mutation_structural_analysis_ncbi\venv\Lib\site-packages)
In [66]:
from Bio.KEGG import REST
import pandas as pd

print("Searching KEGG for 'blaTEM' related entries...")
result = REST.kegg_find("genes", "blaTEM").read()

kegg_entries = []
if result:
    for line in result.strip().split('\n'):
        parts = line.split('\t')
        if len(parts) > 1:
            kegg_id = parts[0]
            description = parts[1]
            kegg_entries.append({'KEGG ID': kegg_id, 'Description': description})
else:
    print("No KEGG entries found for 'blaTEM'.")

if kegg_entries:
    df_kegg_entries = pd.DataFrame(kegg_entries)
    print("\nFound KEGG entries:")
    print(df_kegg_entries.to_string())


    if not df_kegg_entries.empty:
        first_kegg_id = df_kegg_entries['KEGG ID'].iloc[0]
        print(f"\nRetrieving pathways for KEGG ID: {first_kegg_id}...")
        pathway_results = REST.kegg_link("pathway", first_kegg_id).read()

        kegg_pathways = []
        if pathway_results:
            for line in pathway_results.strip().split('\n'):
                parts = line.split('\t')
                if len(parts) > 1:
                    path_id = parts[1]
                    path_info = REST.kegg_get(path_id).read()
                    path_name = "N/A"
                    for p_line in path_info.split('\n'):
                        if p_line.startswith("NAME"):
                            path_name = p_line.split("  ")[1].strip()
                            break
                    kegg_pathways.append({'Pathway ID': path_id, 'Pathway Name': path_name})
            df_kegg_pathways = pd.DataFrame(kegg_pathways)
            print("\nAssociated KEGG Pathways:")
            print(df_kegg_pathways.to_string())
        else:
            print(f"No pathways found for {first_kegg_id}.")
else:
    print("No KEGG entries to retrieve pathways for.")
Searching KEGG for 'blaTEM' related entries...

Found KEGG entries:
            KEGG ID                                          Description
0  ecos:EC958_A0053                                      blaTEM-1; TEM-1
1   cfq:C2U38_26795  blaTEM; class A broad-spectrum beta-lactamase TEM-1
2   cir:C2U53_00280  blaTEM; class A broad-spectrum beta-lactamase TEM-1
3   cie:AN232_27700  blaTEM; class A broad-spectrum beta-lactamase TEM-1
4   cie:AN232_30620  blaTEM; class A broad-spectrum beta-lactamase TEM-1
5   ebc:C2U52_00385  blaTEM; class A broad-spectrum beta-lactamase TEM-1
6    abn:AB57_06335                                        blaTEM; TEM-1
7   nsi:A6J88_09500  blaTEM; class A broad-spectrum beta-lactamase TEM-1
8     bww:bwei_5861            blaTEM-116; ampicillin resistance protein

Retrieving pathways for KEGG ID: ecos:EC958_A0053...

Associated KEGG Pathways:
       Pathway ID Pathway Name
0  path:ecos01501             
In [67]:
if not df_kegg_pathways.empty:
    example_path_id = df_kegg_pathways['Pathway ID'].iloc[0] 
    print(f"\nGetting details for pathway: {example_path_id}")
    pathway_details = REST.kegg_get(example_path_id).read()
    print(pathway_details)
Getting details for pathway: path:ecos01501
ENTRY       ecos01501                   Pathway
NAME        beta-Lactam resistance - Escherichia coli O25b:K100:H4-ST131 EC958 (UPEC)
DESCRIPTION The beta-lactam antibiotics are the most widely used group of antibiotics, which exert their effect by interfering with the structural crosslinking of peptidoglycans in bacterial cell walls. Over the past decades, a rapid increase in the number of beta-lactam-resistant clinical isolates is observed. Bacterial resistance to beta-lactam antibiotics can be achieved by any of the following strategies: producing inactivating enzymes called beta-lactamases, altering the beta-lactam targets of penicillin-binding proteins (PBPs), reducing transport of beta-lactams into the periplasmic space via changes in porins, and using the mechanisms for exclusion of beta-lactams by way of efflux pumps. Resistance may result from intrinsic properties of organisms, through gene mutations, and through plasmid- and transposon-specified genes.
CLASS       Human Diseases; Drug resistance: antimicrobial
PATHWAY_MAP ecos01501  beta-Lactam resistance
ORGANISM    Escherichia coli O25b:K100:H4-ST131 EC958 (UPEC) [GN:ecos]
REFERENCE   PMID:23034325
  AUTHORS   Fernandez L, Hancock RE
  TITLE     Adaptive and mutational resistance: role of porins and efflux pumps in drug resistance.
  JOURNAL   Clin Microbiol Rev 25:661-81 (2012)
            DOI:10.1128/CMR.00043-12
REFERENCE   PMID:21149619
  AUTHORS   Muller C, Plesiat P, Jeannot K
  TITLE     A two-component regulatory system interconnects resistance to polymyxins, aminoglycosides, fluoroquinolones, and beta-lactams in Pseudomonas aeruginosa.
  JOURNAL   Antimicrob Agents Chemother 55:1211-21 (2011)
            DOI:10.1128/AAC.01252-10
REFERENCE   PMID:20351243
  AUTHORS   Tanabe M, Nimigean CM, Iverson TM
  TITLE     Structural basis for solute transport, nucleotide regulation, and immunological recognition of Neisseria meningitidis PorB.
  JOURNAL   Proc Natl Acad Sci U S A 107:6811-6 (2010)
            DOI:10.1073/pnas.0912115107
REFERENCE   PMID:9797206
  AUTHORS   Gill MJ, Simjee S, Al-Hattawi K, Robertson BD, Easmon CS, Ison CA
  TITLE     Gonococcal resistance to beta-lactams and tetracycline involves mutation in loop 3 of the porin encoded at the penB locus.
  JOURNAL   Antimicrob Agents Chemother 42:2799-803 (1998)
            DOI:10.1128/AAC.42.11.2799
REFERENCE   PMID:23163477
  AUTHORS   Johnson JW, Fisher JF, Mobashery S
  TITLE     Bacterial cell-wall recycling.
  JOURNAL   Ann N Y Acad Sci 1277:54-75 (2013)
            DOI:10.1111/j.1749-6632.2012.06813.x
REFERENCE   PMID:22438804
  AUTHORS   Amoroso A, Boudet J, Berzigotti S, Duval V, Teller N, Mengin-Lecreulx D, Luxen A, Simorre JP, Joris B
  TITLE     A peptidoglycan fragment triggers beta-lactam resistance in Bacillus licheniformis.
  JOURNAL   PLoS Pathog 8:e1002571 (2012)
            DOI:10.1371/journal.ppat.1002571
REFERENCE   PMID:19154333
  AUTHORS   Sala C, Haouz A, Saul FA, Miras I, Rosenkrands I, Alzari PM, Cole ST
  TITLE     Genome-wide regulon and crystal structure of BlaI (Rv1846c) from Mycobacterium tuberculosis.
  JOURNAL   Mol Microbiol 71:1102-16 (2009)
            DOI:10.1111/j.1365-2958.2008.06583.x
REFERENCE   PMID:18248419
  AUTHORS   Zapun A, Contreras-Martel C, Vernet T
  TITLE     Penicillin-binding proteins and beta-lactam resistance.
  JOURNAL   FEMS Microbiol Rev 32:361-85 (2008)
            DOI:10.1111/j.1574-6976.2007.00095.x
REFERENCE   PMID:19258280
  AUTHORS   Vettoretti L, Plesiat P, Muller C, El Garch F, Phan G, Attree I, Ducruix A, Llanes C
  TITLE     Efflux unbalance in Pseudomonas aeruginosa isolates from cystic fibrosis patients.
  JOURNAL   Antimicrob Agents Chemother 53:1987-97 (2009)
            DOI:10.1128/AAC.01024-08
REFERENCE   PMID:15387820
  AUTHORS   Cao L, Srikumar R, Poole K
  TITLE     MexAB-OprM hyperexpression in NalC-type multidrug-resistant Pseudomonas aeruginosa: identification and characterization of the nalC gene encoding a repressor of PA3720-PA3719.
  JOURNAL   Mol Microbiol 53:1423-36 (2004)
            DOI:10.1111/j.1365-2958.2004.04210.x
REFERENCE   PMID:11895293
  AUTHORS   Poole K, Srikumar R
  TITLE     Multidrug efflux in Pseudomonas aeruginosa: components, mechanisms and clinical significance.
  JOURNAL   Curr Top Med Chem 1:59-71 (2001)
            DOI:10.2174/1568026013395605
REFERENCE   PMID:15855496
  AUTHORS   Sobel ML, Hocquet D, Cao L, Plesiat P, Poole K
  TITLE     Mutations in PA3574 (nalD) lead to increased MexAB-OprM expression and multidrug resistance in laboratory and clinical isolates of Pseudomonas aeruginosa.
  JOURNAL   Antimicrob Agents Chemother 49:1782-6 (2005)
            DOI:10.1128/AAC.49.5.1782-1786.2005
REFERENCE   PMID:15105114
  AUTHORS   Kaczmarek FS, Gootz TD, Dib-Hajj F, Shang W, Hallowell S, Cronan M
  TITLE     Genetic and molecular characterization of beta-lactamase-negative ampicillin-resistant Haemophilus influenzae with unusually high resistance to ampicillin.
  JOURNAL   Antimicrob Agents Chemother 48:1630-9 (2004)
            DOI:10.1128/AAC.48.5.1630-1639.2004
REFERENCE   PMID:16048914
  AUTHORS   Dean CR, Narayan S, Daigle DM, Dzink-Fox JL, Puyang X, Bracken KR, Dean KE, Weidmann B, Yuan Z, Jain R, Ryder NS
  TITLE     Role of the AcrAB-TolC efflux pump in determining susceptibility of Haemophilus influenzae to the novel peptide deformylase inhibitor LBM415.
  JOURNAL   Antimicrob Agents Chemother 49:3129-35 (2005)
            DOI:10.1128/AAC.49.8.3129-3135.2005
REFERENCE   PMID:22371895
  AUTHORS   Rosenfeld N, Bouchier C, Courvalin P, Perichon B
  TITLE     Expression of the resistance-nodulation-cell division pump AdeIJK in Acinetobacter baumannii is regulated by AdeN, a TetR-type regulator.
  JOURNAL   Antimicrob Agents Chemother 56:2504-10 (2012)
            DOI:10.1128/AAC.06422-11
REFERENCE   PMID:21173183
  AUTHORS   Coyne S, Courvalin P, Perichon B
  TITLE     Efflux-mediated antibiotic resistance in Acinetobacter spp.
  JOURNAL   Antimicrob Agents Chemother 55:947-53 (2011)
            DOI:10.1128/AAC.01388-10
REFERENCE   PMID:19026770
  AUTHORS   Nikaido H, Takatsuka Y
  TITLE     Mechanisms of RND multidrug efflux pumps.
  JOURNAL   Biochim Biophys Acta 1794:769-81 (2009)
            DOI:10.1016/j.bbapap.2008.10.004
REFERENCE   PMID:17277059
  AUTHORS   Truong-Bolduc QC, Hooper DC
  TITLE     The transcriptional regulators NorG and MgrA modulate resistance to both quinolones and beta-lactams in Staphylococcus aureus.
  JOURNAL   J Bacteriol 189:2996-3005 (2007)
            DOI:10.1128/JB.01819-06
REFERENCE   PMID:12222968
  AUTHORS   Sauvage E, Kerff F, Fonze E, Herman R, Schoot B, Marquette JP, Taburet Y, Prevost D, Dumas J, Leonard G, Stefanic P, Coyette J, Charlier P
  TITLE     The 2.4-A crystal structure of the penicillin-resistant penicillin-binding protein PBP5fm from Enterococcus faecium in complex with benzylpenicillin.
  JOURNAL   Cell Mol Life Sci 59:1223-32 (2002)
            DOI:10.1007/s00018-002-8500-0
REFERENCE   PMID:16143832
  AUTHORS   Fuda CC, Fisher JF, Mobashery S
  TITLE     Beta-lactam resistance in Staphylococcus aureus: the adaptive resistance of a plastic genome.
  JOURNAL   Cell Mol Life Sci 62:2617-33 (2005)
            DOI:10.1007/s00018-005-5148-6
REL_PATHWAY ecos00550  Peptidoglycan biosynthesis
KO_PATHWAY  ko01501
///

In [71]:
import pandas as pd
import matplotlib.pyplot as plt

snp_df = pd.read_csv("snp_table.csv")

plt.figure(figsize=(24, 12))
plt.bar(snp_df["Position"], snp_df["Variants"].str.len(), color="skyblue")
plt.xlabel("Position in Sequence")
plt.ylabel("Number of Variants")
plt.title("Distribution of SNPs in blaTEM Sequences")
plt.tight_layout()
plt.savefig("snp_distribution.png", dpi=300)
plt.show()
No description has been provided for this image
In [75]:
import numpy as np
from Bio import AlignIO
import matplotlib.pyplot as plt

alignment = AlignIO.read("aligned_sequences.aln", "fasta")

window_size = 100
step_size = 50
pi_values = []

for start in range(0, alignment.get_alignment_length() - window_size + 1, step_size):
    window = alignment[:, start:start + window_size]
    pi = 0.0 
    
    for pos in range(window_size):
        column = window[:, pos]  
        freqs = [column.count(b) for b in set(column) if b not in ("-", "N")]
        total = sum(freqs)
        if total > 1:  
            pi_site = 1 - sum((f / total) ** 2 for f in freqs)
            pi += pi_site
    
    pi = pi / window_size if window_size > 0 else 0
    pi_values.append(pi)

positions = range(0, len(pi_values) * step_size, step_size)

plt.figure(figsize=(12, 6))
plt.plot(positions, pi_values, "-o", color="purple")
plt.xlabel("Position in Sequence")
plt.ylabel("Nucleotide Diversity (π)")
plt.title("Sliding Window Analysis of Nucleotide Diversity")
plt.tight_layout()
plt.savefig("nucleotide_diversity_sliding.png", dpi=300)
plt.show()
No description has been provided for this image
In [77]:
from Bio import AlignIO
import matplotlib.pyplot as plt

alignment = AlignIO.read("aligned_sequences.aln", "fasta")

nucleotide_counts = {'A': 0, 'T': 0, 'C': 0, 'G': 0}
for record in alignment:
    for base in record.seq:
        if base in nucleotide_counts:
            nucleotide_counts[base] += 1

total = sum(nucleotide_counts.values())
nucleotide_percentages = {k: v / total * 100 for k, v in nucleotide_counts.items()}

plt.figure(figsize=(8, 8))
plt.pie(nucleotide_percentages.values(), labels=nucleotide_percentages.keys(), autopct='%1.1f%%', colors=['#FF9999', '#66B2FF', '#99FF99', '#FFCC99'])
plt.title("Distribution of Nucleotides in blaTEM Sequences")
plt.savefig("nucleotide_distribution_pie.png", dpi=300)
plt.show()
No description has been provided for this image
In [82]:
from Bio import AlignIO
import seaborn as sns
import matplotlib.pyplot as plt
import numpy as np

alignment = AlignIO.read("aligned_sequences.aln", "fasta")

n_seqs = len(alignment)
similarity_matrix = np.zeros((n_seqs, n_seqs))
for i in range(n_seqs):
    for j in range(n_seqs):
        matches = sum(a == b and a != '-' for a, b in zip(alignment[i].seq, alignment[j].seq))
        total = sum(1 for a, b in zip(alignment[i].seq, alignment[j].seq) if a != '-' and b != '-')
        similarity_matrix[i, j] = matches / total if total > 0 else 0

labels = [rec.id[:10] if len(rec.id) > 10 else rec.id for rec in alignment]  

plt.figure(figsize=(12, 10))  
sns.heatmap(similarity_matrix, 
            annot=True,             
            cmap="RdYlBu_r",         
            vmin=0, vmax=1,          
            xticklabels=labels,      
            yticklabels=labels,      
            annot_kws={"size": 8},  
            square=True,            
            cbar_kws={"shrink": 0.5, "label": "Similarity Score"})  

plt.xticks(rotation=45, ha="right")  
plt.yticks(rotation=0)                
plt.title("Similarity Heatmap of blaTEM Sequences", pad=20, size=14)
plt.xlabel("Sequence ID")
plt.ylabel("Sequence ID")

plt.tight_layout()
plt.savefig("similarity_heatmap_improved.png", dpi=300, bbox_inches="tight")
plt.show()
No description has been provided for this image
In [79]:
import pandas as pd
import matplotlib.pyplot as plt

lengths_df = pd.read_csv("sequence_lengths.csv")

plt.figure(figsize=(10, 6))
plt.plot(lengths_df.index, lengths_df["length"], "-o", color="green")
plt.xlabel("Sequence Index")
plt.ylabel("Length (bp)")
plt.title("Distribution of Filtered Sequence Lengths")
plt.grid(True)
plt.savefig("sequence_length_distribution.png", dpi=300)
plt.show()
No description has been provided for this image
In [80]:
from Bio import SeqIO
import pandas as pd

original_records = list(SeqIO.parse("tem1_sequences.fasta", "fasta"))
filtered_records = list(SeqIO.parse("filtered_sequences.fasta", "fasta"))

original_lengths = [len(r.seq) for r in original_records]
filtered_lengths = [len(r.seq) for r in filtered_records]

stats = {
    "Dataset": ["Original", "Filtered"],
    "Number of Sequences": [len(original_records), len(filtered_records)],
    "Mean Length": [round(sum(original_lengths) / len(original_lengths), 2), round(sum(filtered_lengths) / len(filtered_lengths), 2)],
    "Standard Deviation": [round(pd.Series(original_lengths).std(), 2), round(pd.Series(filtered_lengths).std(), 2)]
}

stats_df = pd.DataFrame(stats)
print(stats_df.to_string(index=False))
 Dataset  Number of Sequences  Mean Length  Standard Deviation
Original                   93    186156.78           877423.88
Filtered                   47      1052.53              637.47
In [83]:
from Bio import AlignIO
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

alignment = AlignIO.read("aligned_sequences.aln", "fasta")
window_size = 100
step_size = 50
pi_values = []
snp_counts = []

for start in range(0, alignment.get_alignment_length() - window_size + 1, step_size):
    window = alignment[:, start:start + window_size]
    pi = 0.0
    snps = 0
    for pos in range(window_size):
        column = window[:, pos]
        bases = [b for b in column if b not in ("-", "N")]
        if len(set(bases)) > 1:
            snps += 1
        freqs = [bases.count(b) for b in set(bases)]
        total = sum(freqs)
        if total > 1:
            pi_site = 1 - sum((f / total) ** 2 for f in freqs)
            pi += pi_site
    pi_values.append(pi / window_size if window_size > 0 else 0)
    snp_counts.append(snps)

positions = np.arange(0, len(pi_values) * step_size, step_size)
lengths = [len(rec.seq) for rec in alignment]  

fig = plt.figure(figsize=(10, 8))
ax = fig.add_subplot(111, projection='3d')
scatter = ax.scatter(positions, pi_values, snp_counts, c=pi_values, cmap='viridis')
ax.set_xlabel("Position in Sequence")
ax.set_ylabel("Nucleotide Diversity (π)")
ax.set_zlabel("Number of SNPs")
plt.title("3D Scatter Plot of Nucleotide Diversity and SNPs")
plt.colorbar(scatter, label="Diversity Intensity")
plt.savefig("3d_nucleotide_diversity.png", dpi=300)
plt.show()
No description has been provided for this image
In [84]:
from Bio import AlignIO
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns

alignment = AlignIO.read("aligned_sequences.aln", "fasta")

n_positions = alignment.get_alignment_length()
nucleotide_freqs = {base: [] for base in "ATCG"}
for pos in range(n_positions):
    column = alignment[:, pos]
    total = sum(1 for b in column if b not in ("-", "N"))
    for base in "ATCG":
        freq = column.count(base) / total if total > 0 else 0
        nucleotide_freqs[base].append(freq)

data = pd.DataFrame(nucleotide_freqs, index=range(n_positions))

plt.figure(figsize=(12, 6))
plt.stackplot(range(n_positions), data["A"], data["T"], data["C"], data["G"], 
              labels=["A", "T", "C", "G"], colors=["#FF9999", "#66B2FF", "#99FF99", "#FFCC99"])
plt.legend(loc="upper right")
plt.xlabel("Position in Sequence")
plt.ylabel("Frequency")
plt.title("Streamgraph of Nucleotide Frequencies")
plt.savefig("nucleotide_streamgraph.png", dpi=300)
plt.show()
No description has been provided for this image
In [85]:
from Bio import SeqIO
import matplotlib.pyplot as plt

records = list(SeqIO.parse("filtered_sequences.fasta", "fasta"))
lengths = [len(rec.seq) for rec in records]
snp_counts = [sum(1 for i in range(len(rec.seq)-1) if rec.seq[i] != rec.seq[i+1]) for rec in records]  
diversity = [0.5 - abs(0.5 - i/len(lengths)) for i in range(len(lengths))] 

plt.figure(figsize=(10, 6))
plt.scatter(lengths, range(len(records)), s=[s * 100 for s in snp_counts], c=diversity, cmap="RdYlGn", alpha=0.6)
plt.colorbar(label="Nucleotide Diversity (π)")
plt.xlabel("Sequence Length (bp)")
plt.ylabel("Sequence Index")
plt.title("Bubble Chart of Sequence Diversity and SNPs")
plt.savefig("bubble_chart_diversity.png", dpi=300)
plt.show()
No description has been provided for this image
In [94]:
from Bio import AlignIO
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

alignment = AlignIO.read("aligned_sequences.aln", "fasta")

snp_positions = []
for pos in range(alignment.get_alignment_length() - 1):
    column = alignment[:, pos]
    next_column = alignment[:, pos + 1]
    if len(set(column)) > 1 or len(set(next_column)) > 1:
        snp_positions.append(pos)

theta = np.linspace(0, 2 * np.pi, len(snp_positions))
phi = np.pi * np.random.rand(len(snp_positions))
x = np.sin(phi) * np.cos(theta)
y = np.sin(phi) * np.sin(theta)
z = np.cos(phi)

fig = plt.figure(figsize=(10, 10))
ax = fig.add_subplot(111, projection='3d')
scatter = ax.scatter(x, y, z, c=snp_positions, cmap='plasma')
ax.set_xlabel("X")
ax.set_ylabel("Y")
ax.set_zlabel("Z")
plt.title("Spherical Plot of SNP Positions")
plt.colorbar(scatter, label="Position Index")
plt.savefig("spherical_snp_plot.png", dpi=300)
plt.show()
No description has been provided for this image
In [112]:
from Bio import AlignIO
import matplotlib.pyplot as plt
import numpy as np

alignment = AlignIO.read("aligned_sequences.aln", "fasta")

n_sequences = len(alignment)
colors = {'A': '#FF9999', 'T': '#66B2FF', 'C': '#99FF99', 'G': '#FFCC99', '-': '#D3D3D3'}

plt.figure(figsize=(15, n_sequences * 2))  
for i, record in enumerate(alignment):
    sequence = str(record.seq)
    positions = range(len(sequence))
    y_offset = i  
    for j, base in enumerate(sequence):
        plt.scatter(j, y_offset, c=colors.get(base, '#000000'), s=100, alpha=0.6)

plt.title("Gene Art Visualization of All blaTEM Sequences")
plt.xlabel("Position")
plt.ylabel("Sequence Index")
plt.yticks(range(n_sequences), [f"Seq {i+1}" for i in range(n_sequences)])  
plt.tight_layout()
plt.savefig("gene_art_all_sequences.png", dpi=300)
plt.show()
---------------------------------------------------------------------------
KeyboardInterrupt                         Traceback (most recent call last)
Cell In[112], line 19
     17     y_offset = i  # استخدام فهرس التسلسل كمحور Y
     18     for j, base in enumerate(sequence):
---> 19         plt.scatter(j, y_offset, c=colors.get(base, '#000000'), s=100, alpha=0.6)
     21 # إعداد الرسم
     22 plt.title("Gene Art Visualization of All blaTEM Sequences")

File D:\Osama\biotec\Bioinformatics\mutation_structural_analysis_ncbi\venv\Lib\site-packages\matplotlib\_api\deprecation.py:453, in make_keyword_only.<locals>.wrapper(*args, **kwargs)
    447 if len(args) > name_idx:
    448     warn_deprecated(
    449         since, message="Passing the %(name)s %(obj_type)s "
    450         "positionally is deprecated since Matplotlib %(since)s; the "
    451         "parameter will become keyword-only in %(removal)s.",
    452         name=name, obj_type=f"parameter of {func.__name__}()")
--> 453 return func(*args, **kwargs)

File D:\Osama\biotec\Bioinformatics\mutation_structural_analysis_ncbi\venv\Lib\site-packages\matplotlib\pyplot.py:3948, in scatter(x, y, s, c, marker, cmap, norm, vmin, vmax, alpha, linewidths, edgecolors, colorizer, plotnonfinite, data, **kwargs)
   3928 @_copy_docstring_and_deprecators(Axes.scatter)
   3929 def scatter(
   3930     x: float | ArrayLike,
   (...)   3946     **kwargs,
   3947 ) -> PathCollection:
-> 3948     __ret = gca().scatter(
   3949         x,
   3950         y,
   3951         s=s,
   3952         c=c,
   3953         marker=marker,
   3954         cmap=cmap,
   3955         norm=norm,
   3956         vmin=vmin,
   3957         vmax=vmax,
   3958         alpha=alpha,
   3959         linewidths=linewidths,
   3960         edgecolors=edgecolors,
   3961         colorizer=colorizer,
   3962         plotnonfinite=plotnonfinite,
   3963         **({"data": data} if data is not None else {}),
   3964         **kwargs,
   3965     )
   3966     sci(__ret)
   3967     return __ret

File D:\Osama\biotec\Bioinformatics\mutation_structural_analysis_ncbi\venv\Lib\site-packages\matplotlib\_api\deprecation.py:453, in make_keyword_only.<locals>.wrapper(*args, **kwargs)
    447 if len(args) > name_idx:
    448     warn_deprecated(
    449         since, message="Passing the %(name)s %(obj_type)s "
    450         "positionally is deprecated since Matplotlib %(since)s; the "
    451         "parameter will become keyword-only in %(removal)s.",
    452         name=name, obj_type=f"parameter of {func.__name__}()")
--> 453 return func(*args, **kwargs)

File D:\Osama\biotec\Bioinformatics\mutation_structural_analysis_ncbi\venv\Lib\site-packages\matplotlib\__init__.py:1521, in _preprocess_data.<locals>.inner(ax, data, *args, **kwargs)
   1518 @functools.wraps(func)
   1519 def inner(ax, *args, data=None, **kwargs):
   1520     if data is None:
-> 1521         return func(
   1522             ax,
   1523             *map(cbook.sanitize_sequence, args),
   1524             **{k: cbook.sanitize_sequence(v) for k, v in kwargs.items()})
   1526     bound = new_sig.bind(ax, *args, **kwargs)
   1527     auto_label = (bound.arguments.get(label_namer)
   1528                   or bound.kwargs.get(label_namer))

File D:\Osama\biotec\Bioinformatics\mutation_structural_analysis_ncbi\venv\Lib\site-packages\matplotlib\axes\_axes.py:5065, in Axes.scatter(self, x, y, s, c, marker, cmap, norm, vmin, vmax, alpha, linewidths, edgecolors, colorizer, plotnonfinite, **kwargs)
   5062     if self._ymargin < 0.05 and x.size > 0:
   5063         self.set_ymargin(0.05)
-> 5065 self.add_collection(collection)
   5066 self._request_autoscale_view()
   5068 return collection

File D:\Osama\biotec\Bioinformatics\mutation_structural_analysis_ncbi\venv\Lib\site-packages\matplotlib\axes\_base.py:2366, in _AxesBase.add_collection(self, collection, autolim)
   2361     collection.set_clip_path(self.patch)
   2363 if autolim:
   2364     # Make sure viewLim is not stale (mostly to match
   2365     # pre-lazy-autoscale behavior, which is not really better).
-> 2366     self._unstale_viewLim()
   2367     datalim = collection.get_datalim(self.transData)
   2368     points = datalim.get_points()

File D:\Osama\biotec\Bioinformatics\mutation_structural_analysis_ncbi\venv\Lib\site-packages\matplotlib\axes\_base.py:898, in _AxesBase._unstale_viewLim(self)
    896     for ax in self._shared_axes[name].get_siblings(self):
    897         ax._stale_viewlims[name] = False
--> 898 self.autoscale_view(**{f"scale{name}": scale
    899                        for name, scale in need_scale.items()})

File D:\Osama\biotec\Bioinformatics\mutation_structural_analysis_ncbi\venv\Lib\site-packages\matplotlib\axes\_base.py:3002, in _AxesBase.autoscale_view(self, tight, scalex, scaley)
   2997         x_stickies = np.sort(np.concatenate([
   2998             artist.sticky_edges.x
   2999             for ax in self._shared_axes["x"].get_siblings(self)
   3000             for artist in ax.get_children()]))
   3001     if self._ymargin and scaley and self.get_autoscaley_on():
-> 3002         y_stickies = np.sort(np.concatenate([
   3003             artist.sticky_edges.y
   3004             for ax in self._shared_axes["y"].get_siblings(self)
   3005             for artist in ax.get_children()]))
   3006 if self.get_xscale() == 'log':
   3007     x_stickies = x_stickies[x_stickies > 0]

File D:\Osama\biotec\Bioinformatics\mutation_structural_analysis_ncbi\venv\Lib\site-packages\numpy\_core\fromnumeric.py:965, in _sort_dispatcher(a, axis, kind, order, stable)
    878     """
    879     Perform an indirect partition along the given axis using the
    880     algorithm specified by the `kind` keyword. It returns an array of
   (...)    960 
    961     """
    962     return _wrapfunc(a, 'argpartition', kth, axis=axis, kind=kind, order=order)
--> 965 def _sort_dispatcher(a, axis=None, kind=None, order=None, *, stable=None):
    966     return (a,)
    969 @array_function_dispatch(_sort_dispatcher)
    970 def sort(a, axis=-1, kind=None, order=None, *, stable=None):

KeyboardInterrupt: 
Error in callback <function _draw_all_if_interactive at 0x0000020A42AEC400> (for post_execute), with arguments args (),kwargs {}:
---------------------------------------------------------------------------
KeyboardInterrupt                         Traceback (most recent call last)
File D:\Osama\biotec\Bioinformatics\mutation_structural_analysis_ncbi\venv\Lib\site-packages\matplotlib\pyplot.py:279, in _draw_all_if_interactive()
    277 def _draw_all_if_interactive() -> None:
    278     if matplotlib.is_interactive():
--> 279         draw_all()

File D:\Osama\biotec\Bioinformatics\mutation_structural_analysis_ncbi\venv\Lib\site-packages\matplotlib\_pylab_helpers.py:131, in Gcf.draw_all(cls, force)
    129 for manager in cls.get_all_fig_managers():
    130     if force or manager.canvas.figure.stale:
--> 131         manager.canvas.draw_idle()

File D:\Osama\biotec\Bioinformatics\mutation_structural_analysis_ncbi\venv\Lib\site-packages\matplotlib\backend_bases.py:1891, in FigureCanvasBase.draw_idle(self, *args, **kwargs)
   1889 if not self._is_idle_drawing:
   1890     with self._idle_draw_cntx():
-> 1891         self.draw(*args, **kwargs)

File D:\Osama\biotec\Bioinformatics\mutation_structural_analysis_ncbi\venv\Lib\site-packages\matplotlib\backends\backend_agg.py:382, in FigureCanvasAgg.draw(self)
    379 # Acquire a lock on the shared font cache.
    380 with (self.toolbar._wait_cursor_for_draw_cm() if self.toolbar
    381       else nullcontext()):
--> 382     self.figure.draw(self.renderer)
    383     # A GUI class may be need to update a window using this draw, so
    384     # don't forget to call the superclass.
    385     super().draw()

File D:\Osama\biotec\Bioinformatics\mutation_structural_analysis_ncbi\venv\Lib\site-packages\matplotlib\artist.py:94, in _finalize_rasterization.<locals>.draw_wrapper(artist, renderer, *args, **kwargs)
     92 @wraps(draw)
     93 def draw_wrapper(artist, renderer, *args, **kwargs):
---> 94     result = draw(artist, renderer, *args, **kwargs)
     95     if renderer._rasterizing:
     96         renderer.stop_rasterizing()

File D:\Osama\biotec\Bioinformatics\mutation_structural_analysis_ncbi\venv\Lib\site-packages\matplotlib\artist.py:71, in allow_rasterization.<locals>.draw_wrapper(artist, renderer)
     68     if artist.get_agg_filter() is not None:
     69         renderer.start_filter()
---> 71     return draw(artist, renderer)
     72 finally:
     73     if artist.get_agg_filter() is not None:

File D:\Osama\biotec\Bioinformatics\mutation_structural_analysis_ncbi\venv\Lib\site-packages\matplotlib\figure.py:3257, in Figure.draw(self, renderer)
   3254             # ValueError can occur when resizing a window.
   3256     self.patch.draw(renderer)
-> 3257     mimage._draw_list_compositing_images(
   3258         renderer, self, artists, self.suppressComposite)
   3260     renderer.close_group('figure')
   3261 finally:

File D:\Osama\biotec\Bioinformatics\mutation_structural_analysis_ncbi\venv\Lib\site-packages\matplotlib\image.py:134, in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
    132 if not_composite or not has_images:
    133     for a in artists:
--> 134         a.draw(renderer)
    135 else:
    136     # Composite any adjacent images together
    137     image_group = []

File D:\Osama\biotec\Bioinformatics\mutation_structural_analysis_ncbi\venv\Lib\site-packages\matplotlib\artist.py:71, in allow_rasterization.<locals>.draw_wrapper(artist, renderer)
     68     if artist.get_agg_filter() is not None:
     69         renderer.start_filter()
---> 71     return draw(artist, renderer)
     72 finally:
     73     if artist.get_agg_filter() is not None:

File D:\Osama\biotec\Bioinformatics\mutation_structural_analysis_ncbi\venv\Lib\site-packages\matplotlib\axes\_base.py:3216, in _AxesBase.draw(self, renderer)
   3213 if artists_rasterized:
   3214     _draw_rasterized(self.get_figure(root=True), artists_rasterized, renderer)
-> 3216 mimage._draw_list_compositing_images(
   3217     renderer, self, artists, self.get_figure(root=True).suppressComposite)
   3219 renderer.close_group('axes')
   3220 self.stale = False

File D:\Osama\biotec\Bioinformatics\mutation_structural_analysis_ncbi\venv\Lib\site-packages\matplotlib\image.py:134, in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
    132 if not_composite or not has_images:
    133     for a in artists:
--> 134         a.draw(renderer)
    135 else:
    136     # Composite any adjacent images together
    137     image_group = []

File D:\Osama\biotec\Bioinformatics\mutation_structural_analysis_ncbi\venv\Lib\site-packages\matplotlib\artist.py:71, in allow_rasterization.<locals>.draw_wrapper(artist, renderer)
     68     if artist.get_agg_filter() is not None:
     69         renderer.start_filter()
---> 71     return draw(artist, renderer)
     72 finally:
     73     if artist.get_agg_filter() is not None:

File D:\Osama\biotec\Bioinformatics\mutation_structural_analysis_ncbi\venv\Lib\site-packages\matplotlib\collections.py:1008, in _CollectionWithSizes.draw(self, renderer)
   1005 @artist.allow_rasterization
   1006 def draw(self, renderer):
   1007     self.set_sizes(self._sizes, self.get_figure(root=True).dpi)
-> 1008     super().draw(renderer)

File D:\Osama\biotec\Bioinformatics\mutation_structural_analysis_ncbi\venv\Lib\site-packages\matplotlib\artist.py:71, in allow_rasterization.<locals>.draw_wrapper(artist, renderer)
     68     if artist.get_agg_filter() is not None:
     69         renderer.start_filter()
---> 71     return draw(artist, renderer)
     72 finally:
     73     if artist.get_agg_filter() is not None:

File D:\Osama\biotec\Bioinformatics\mutation_structural_analysis_ncbi\venv\Lib\site-packages\matplotlib\collections.py:398, in Collection.draw(self, renderer)
    396 else:
    397     combined_transform = transform
--> 398 extents = paths[0].get_extents(combined_transform)
    399 if (extents.width < self.get_figure(root=True).bbox.width
    400         and extents.height < self.get_figure(root=True).bbox.height):
    401     do_single_path_optimization = True

File D:\Osama\biotec\Bioinformatics\mutation_structural_analysis_ncbi\venv\Lib\site-packages\matplotlib\path.py:628, in Path.get_extents(self, transform, **kwargs)
    626 if self.codes is None:
    627     xys = self.vertices
--> 628 elif len(np.intersect1d(self.codes, [Path.CURVE3, Path.CURVE4])) == 0:
    629     # Optimization for the straight line case.
    630     # Instead of iterating through each curve, consider
    631     # each line segment's end-points
    632     # (recall that STOP and CLOSEPOLY vertices are ignored)
    633     xys = self.vertices[np.isin(self.codes,
    634                                 [Path.MOVETO, Path.LINETO])]
    635 else:

File D:\Osama\biotec\Bioinformatics\mutation_structural_analysis_ncbi\venv\Lib\site-packages\numpy\lib\_arraysetops_impl.py:692, in intersect1d(ar1, ar2, assume_unique, return_indices)
    690     aux = aux[aux_sort_indices]
    691 else:
--> 692     aux.sort()
    694 mask = aux[1:] == aux[:-1]
    695 int1d = aux[:-1][mask]

KeyboardInterrupt: 
No description has been provided for this image
In [115]:
from Bio import AlignIO
import matplotlib.pyplot as plt

alignment = AlignIO.read("aligned_sequences.aln", "fasta")
window_size = 100
step_size = 50
pi_values = []

for start in range(0, alignment.get_alignment_length() - window_size + 1, step_size):
    window = alignment[:, start:start + window_size]
    pi = 0.0
    for pos in range(window_size):
        column = [record.seq[pos] for record in window if record.seq[pos] not in ("-", "N")]
        if len(set(column)) > 1:
            freqs = [column.count(b) for b in set(column)]
            total = sum(freqs)
            pi += 1 - sum((f / total) ** 2 for f in freqs)
    pi_values.append(pi / window_size if window_size > 0 else 0)

fig, ax = plt.subplots(figsize=(8, 8))
for i, pi in enumerate(pi_values):
    ax.add_patch(plt.Circle((0, 0), radius=pi * 10, color='b', alpha=0.5, fill=False))
ax.set_xlim(-1, 1)
ax.set_ylim(-1, 1)
ax.set_aspect('equal')
plt.title("Nucleotide diversity circles")
plt.savefig("concentric_circles_diversity.png", dpi=300)
plt.show()
No description has been provided for this image
In [117]:
from Bio import AlignIO
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

# قراءة المحاذاة
alignment = AlignIO.read("aligned_sequences.aln", "fasta")
n_positions = alignment.get_alignment_length()
n_sequences = len(alignment)

# حساب الترددات
freq_A = [sum(1 for record in alignment if record.seq[pos] == 'A') / n_sequences for pos in range(n_positions)]
freq_T = [sum(1 for record in alignment if record.seq[pos] == 'T') / n_sequences for pos in range(n_positions)]
freq_C = [sum(1 for record in alignment if record.seq[pos] == 'C') / n_sequences for pos in range(n_positions)]
freq_G = [sum(1 for record in alignment if record.seq[pos] == 'G') / n_sequences for pos in range(n_positions)]

# إعداد البيانات
x = np.arange(n_positions)
y = np.array([0, 1, 2, 3])  # لـ A, T, C, G
X, Y = np.meshgrid(x, y)
Z = np.array([freq_A, freq_T, freq_C, freq_G])

# رسم الأعمدة
fig = plt.figure(figsize=(12, 8))
ax = fig.add_subplot(111, projection='3d')
for i in range(4):
    ax.bar3d(X[i], Y[i], 0, 1, 1, Z[i], color=['#FF9999', '#66B2FF', '#99FF99', '#FFCC99'][i])
    
ax.set_xlabel("Location")
ax.set_ylabel("Nucleotide")
ax.set_zlabel("Frequency")
ax.set_yticks([0, 1, 2, 3])
ax.set_yticklabels(['A', 'T', 'C', 'G'])
plt.title("3D Plot of Nucleotide Frequency")
plt.savefig("3d_bar_nucleotide.png", dpi=300)
plt.show()
No description has been provided for this image
In [118]:
from Bio import AlignIO
import matplotlib.pyplot as plt

alignment = AlignIO.read("aligned_sequences.aln", "fasta")
window_size = 100
step_size = 50
pi_values = []

for start in range(0, alignment.get_alignment_length() - window_size + 1, step_size):
    window = alignment[:, start:start + window_size]
    pi = 0.0
    for pos in range(window_size):
        column = [record.seq[pos] for record in window if record.seq[pos] not in ("-", "N")]
        if len(set(column)) > 1:
            freqs = [column.count(b) for b in set(column)]
            total = sum(freqs)
            pi += 1 - sum((f / total) ** 2 for f in freqs)
    pi_values.append(pi / window_size if window_size > 0 else 0)

fig, ax = plt.subplots(figsize=(10, 6))
for i, pi in enumerate(pi_values):
    ax.plot([i, i], [0, pi], 'b-')
ax.set_title("Nucleotide Diversity Tree")
ax.set_xlabel("Window Number")
ax.set_ylabel("Diversity (π)")
plt.savefig("tree_like_diversity.png", dpi=300)
plt.show()
No description has been provided for this image
In [121]:
from Bio import AlignIO
import matplotlib.pyplot as plt
import numpy as np

alignment = AlignIO.read("aligned_sequences.aln", "fasta")
sequence = str(alignment[0].seq)  
colors = {'A': '#FF9999', 'T': '#66B2FF', 'C': '#99FF99', 'G': '#FFCC99', '-': '#D3D3D3'}

theta = np.linspace(0, 2 * np.pi * len(sequence) / 100, len(sequence))
r = np.linspace(0, 10, len(sequence))

fig, ax = plt.subplots(subplot_kw={'projection': 'polar'}, figsize=(8, 8))
for i, base in enumerate(sequence):
    ax.scatter(theta[i], r[i], c=colors.get(base, '#000000'), s=50)
ax.set_title("Nucleotide Helix")
plt.savefig("spiral_nucleotide.png", dpi=300)
plt.show()
No description has been provided for this image
In [ ]: